..你直接写代码导出部就可以了? procedure TForm13.Button1Click(Sender: TObject); var i,n: Integer; xlsApp: Variant; begin if adsMaster.Eof then begin ShowMessage('没有数据!'); exit; end; xlsApp := CreateOleObject('Excel.Application'); xlsapp.WorkBooks.add; xlsApp.Visible := false; xlsApp.WorkSheets[1].Activate; adsMaster.First; i :=1; //填Excel标题行 for n:=1 to adsMaster.FieldCount do xlsApp.Cells[i,n].Value := adsMaster.Fields[n-1].DisplayLabel; While not adsMaster.Eof do begin inc(i);//因在循环前使用了一次填标题行,所以在前面做增量 for n:=1 to adsMaster.FieldCount do begin if adsMaster.Fields[n-1].FieldName = 'WO' then xlsApp.Cells[i,n].Value := '''' + adsMaster.Fields[n-1].AsString else xlsApp.Cells[i,n].Value := adsMaster.Fields[n-1].AsString; end; adsMaster.Next; end; xlsApp.Visible := true; end;
procedure TForm13.Button1Click(Sender: TObject);
var
i,n: Integer;
xlsApp: Variant;
begin
if adsMaster.Eof then begin
ShowMessage('没有数据!');
exit;
end;
xlsApp := CreateOleObject('Excel.Application');
xlsapp.WorkBooks.add;
xlsApp.Visible := false;
xlsApp.WorkSheets[1].Activate; adsMaster.First;
i :=1;
//填Excel标题行
for n:=1 to adsMaster.FieldCount do xlsApp.Cells[i,n].Value := adsMaster.Fields[n-1].DisplayLabel;
While not adsMaster.Eof do begin
inc(i);//因在循环前使用了一次填标题行,所以在前面做增量
for n:=1 to adsMaster.FieldCount do begin
if adsMaster.Fields[n-1].FieldName = 'WO' then xlsApp.Cells[i,n].Value := '''' + adsMaster.Fields[n-1].AsString
else xlsApp.Cells[i,n].Value := adsMaster.Fields[n-1].AsString; end; adsMaster.Next;
end;
xlsApp.Visible := true;
end;
代码太多,我只能告诉你方法了。
ExcelWorksheet1.SaveAs(str,56);
希望对大家有什么帮助