给分吧,可这样实现!
procedure Tfm_bf.BitBtn1Click(Sender: TObject);
var row, i: integer;
begin
if SaveDialog1.Execute then
begin
ExcelApplication1.Connect;
ExcelApplication1.Workbooks.Add(Null, 0);
ExcelWorkBook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorkSheet1.ConnectTo(ExcelWorkBook1.Sheets[1] as _WorkSheet);
{以下是在EXCEL中添加列名}
ExcelWOrkSheet1.Cells.Item[1, 1] := '帐号';
ExcelWOrkSheet1.Cells.Item[1, 2] := '姓名';
ExcelWOrkSheet1.Cells.Item[1, 3] := '工资';
{获取DBF中的数据}
query1.Close;
Query1.SQL.Clear;
query1.SQL.Add('select * from gz ');
Query1.Prepare;
query1.open;
row := 2;
while not Query1.Eof do
begin
for i := 0 to Query1.Fields.Count - 1 do
begin
ExcelWOrkSheet1.Cells.Item[row, i + 1] := Query1.Fields.AsString;
end;
row := row + 1;
Query1.Next;
end;
ExcelWorkBook1.SaveCopyAs(SaveDialog1.FileName);
ExcelWOrkBook1.Close(false);
ExcelApplication1.Disconnect;
ExcelApplication1.Quit;
Screen.Cursor := crDefault;
Application.MessageBox('保存完毕!', '消息', 0);
end;