procedure
PasteToColumn(
var
Buf:
string
; x,count:
integer
;
Var
Sheet:variant);
var
IR2,IR1: ExcelRange;
begin
Clipboard
.
AsText:=Buf;
IDispatch(IR1):=Sheet
.
Cells
.
Item[
1
, x];
IDispatch(IR2):=Sheet
.
Cells
.
Item[count, x];
OLEVariant(Sheet
.
Range[IR1, IR2]).PasteSpecial;
Clipboard
.
Clear;
Buf:=
''
;
end
;
procedure
TForm1
.
ExportToExcel(FileName:
string
);
var
XLApp,Sheet:Variant;
index,x:
Integer
;
str,Buf:
string
;
begin
try
Buf:=
''
;
XLApp:= CreateOleObject(
'Excel.Application'
);
XLApp
.
Visible:=
true
;
XLApp
.
Workbooks
.
Add(-
4167
);
XLApp
.
Workbooks[
1
].WorkSheets[
1
].Name:=
'Отчёт'
;
Sheet:=XLApp
.
Workbooks[
1
].WorkSheets[
'Отчёт'
];
AssignFile(input,filename);
Reset(input);
index:=
1
;
x:=
1
;
while
not
eof(input)
do
begin
Readln(str);
Buf:=Buf+str+#
9
#
10
;
if
index
mod
65536
=
0
then
begin
PasteToColumn(Buf,x,
65536
,Sheet);
x:=x+
1
;
index:=
0
;
application
.
ProcessMessages;
end
;
index:=index+
1
;
end
;
PasteToColumn(Buf,x,index,Sheet);
CloseFile(input);
except
CloseFile(input);
showmessage(
'Ошибка при экспорте данных'
);
end
;
end
;