数据表内容导入excel
Excelapplication1.connect;
Excelapplication1.Workbooks.Add(null,0);
Excelworkbook1.connectto(excelapplication1.workbooks[1]);
Excelworksheet1.connectto(excelworkbook1.sheets[1] as _worksheet);
FieldCounts:=DBGrid1.FieldCount;
//记录数据表字段名
For j:=0 to FieldCounts-1 do
Excelworksheet1.Cells.Item[1,j+1]:=
DBGrid1.Fields[j].FieldName;
//记录数据表数据
i:=2;
Query1.First;
While not Query1.Eof do
Begin
For j:=0 to FieldCounts-1 do
Excelworksheet1.Cells.Item[i,j+1]:=Query1.Fields[j].Value;
i:=i+1;
Query1.Next;
End;
Excelworksheet1.SaveAs(Filename_Label.Caption);
Output_Btn.Enabled:=False;
Query1.First;
excel可以通过ado直接调用
Excelworkbook1.Close;
ExcelApplication1.Quit;