with DataSet do
begin
DisableControls;
fieldNum := dbgrid.fieldCount; //列总数
ICell:=round(fieldnum/2);
ExcelApp.Cells[1,ICell]:=Caption; //表名
for i:=1 to fieldNum do //表
begin
ExcelApp.Cells[2,i]:=Fields[i-1].DisplayName;
end;
first;
i:=3;
while not eof do
begin
for j:=1 to fieldNum do
begin
ExcelApp.Cells[i,j]:=fields[j-1].AsString;
end;
inc(i);
if (i mod 20)=0 then
ExcelApp.Cells[i+10,1].Activate;
next;
end;
ExcelApp.Cells[I+1,1]:='CEPS_TITLE'; //表尾
ICell:=ICell+Round(ICell*2/3);
ExcelApp.Cells[I+1,ICell]:='制表: '; //...
EnableControls;
end;
end;
5) 添加新工作表:
var Temp_Worksheet: _WorkSheet;
begin
Temp_Worksheet:=ExcelWorkbook1.
WorkSheets.Add(EmptyParam,EmptyParam,EmptyParam,EmptyParam,0) as _WorkSheet;
ExcelWorkSheet1.ConnectTo(Temp_WorkSheet);
End;