给你贴一贴,这是我以前使用的例子.
EA1.Connect;
EA1.Visible[0]:=False;
EA1.Workbooks.Add(xlWBATWorkSheet,0);
asheet:=EA1.Worksheets.Item[1];
PrnQuery.First;
for i:=1 to PrnQuery.FieldCount do
asheet.cells[1,i].Value:=PrnQuery.Fields[i-1].DisplayName;
for i:=1 to PrnQuery.RecordCountdo
begin
for j:=1 to PrnQuery.FieldCountdo
asheet.Cells[i+1,j].Value:=PrnQuery.Fields[j-1].AsString;
Application.ProcessMessages;
PrnQuery.Next;
Label3.Caption:=IntToStr(i);
end;
end;
SaveDialog.Execute;
if SaveDialog.FileName<>'noname' then
begin
aSheet.SaveAs(SaveDialog.FileName);
ShowMessage('文件已保存為'+SaveDialog.FileName);
end;
aSheet.Application.Quit;
这是打开一个文件,上面是新增一个文件.
EA1.Workbooks.Open('C:/FV/order/order.xls',EmptyParam,EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,1);