为什么不用ole?
{输出到Excel}
procedure TfrmMain.Button1Click(Sender: TObject);
var
MsExcel: oleVariant;
ExcelSheet1: Variant;
i:integer;
row: integer; //Excel行
begin
try
MsExcel:=CreateOleObject('Excel.Application');
except
MessageBox(Handle,'初始化Excel错误。',
'error',MB_OK +MB_ICONERROR);
exit;
end;
Screen.Cursor:=crHourGlass;
MsExcel.Visible:=False;
MsExcel.WorkBooks.Add;
ExcelSheet1:= MsExcel.WorkBooks[1].WorkSheets[1];
for i:=0 to Query1.Fields.Count -1 do
ExcelSheet1.Cells.Item[1,i+1]:=Query1.Fields.FieldName; //标题
row:=2;
while not Query1.Eof do
begin
for i:=0 to Query1.Fields.Count-1 do
begin
ExcelSheet1.Cells.Item[row,i+1]:=Query1.Fields.AsString;
end;
row:=row+1;
Query1.Next;
end;
MsExcel.Visible:=True;
Screen.Cursor:=crDefault;
end;