给你转一篇文章:
首先建立一個TExcelApplication控件﹐設名為EA1,
var aSheet:variant;
i,j:integer;
begin
EA1.Connect;
EA1.Workbooks.Open('C:/yourexcel.xls',EmptyParam,EmptyParam,EmptyParam,EmptyParam,
EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,EmptyParam,1);
//這是打開某個特定文件
// EA1.Workbooks.Add(xlWBATWorkSheet,0); 直接新增一個Excel文件
EA1.Visible[0]:=False;
aSheet:=EA1.Worksheets.Item[1];
x:=0;
for i:=1 to yourdata.RecordCount do
for j:=1 to yourdata.Fieldcount do
asheet.Cells[i,j].Value:=yourdata.fields[j-1].asstring;
SaveDialog.Execute;
if SaveDialog.FileName<>'noname' then begin
aSheet.SaveAs(SaveDialog.FileName);
ShowMessage('文件已保存為'+SaveDialog.FileName);
end;
aSheet.Application.Quit;
end;