procedure
ExportRecordsetToMSExcel(DestName:
string
; Data: _Recordset);
var
ovExcelApp: OleVariant;
ovExcelWorkbook: OleVariant;
ovWS: OleVariant;
ovRange: OleVariant;
begin
ovExcelApp := CreateOleObject(
'Excel.Application'
);
try
ovExcelWorkbook := ovExcelApp
.
WorkBooks
.
Add;
ovWS := ovExcelWorkbook
.
Worksheets
.
Item[
1
];
ovWS
.
Activate;
ovWS
.
Select;
ovRange := ovWS
.
Range[
'A1'
,
'A1'
];
ovRange
.
Resize[Data
.
RecordCount, Data
.
Fields
.
Count];
ovRange
.
CopyFromRecordset(Data, Data
.
RecordCount, Data
.
Fields
.
Count);
ovWS
.
SaveAs(DestName,
1
,
''
,
''
,
False
,
False
);
finally
ovExcelWorkbook
.
Close(SaveChanges :=
False
);
ovWS := Unassigned;
ovExcelWorkbook := Unassigned;
ovExcelApp := Unassigned;
end
;
end
;