在Delphi中如何调用Excel组件?(50分)

  • 主题发起人 主题发起人 folmorse
  • 开始时间 开始时间
F

folmorse

Unregistered / Unconfirmed
GUEST, unregistred user!
我想将程序中处理的数据倒入到Excel表格中,形成报表。不止如何处理?
请大虾执教! 最好给个例子!
 
procedure Tfw_prn.Button1Click(Sender: TObject);
var i,j:integer;
begin
bk.Disconnect; //用于将EXCEL与DELPHI断开 bk:Texcelworkbook
sheet.Disconnect; //sheet: TExcelWorksheet;
ExcelApplication.Disconnect;//ExcelApplication1: TExcelApplication;
//将button按钮置为禁止
button1.Enabled:=false;
ExcelApplication.Connect;
bk.ConnectTo(ExcelApplication.Workbooks.Add(xlWBATWorksheet,0));
sheet.ConnectTo( bk.Worksheets[1] as _worksheet);
i:=1;
for j:=1 to 5 do
sheet.cells.item[i,j]:=adotable1.fields[j-1].fieldname;
i:=i+1;
//用于控制过程
adotable1.DisableControls;
adotable1.First;
while not adotable1.eof do
begin
for j:=1 to 5 do
sheet.cells.Item[i,j]:=adotable1.Fields[j-1].AsString; //填写记录
sheet.cells.Item[i,j]:=chr(13);//回车
adotable1.next;
i:=i+1;
end;
adotable1.EnableControls;
ExcelApplication.Visible[0] :=true;
bk.Disconnect;
sheet.Disconnect;
ExcelApplication.Disconnect;
//按钮放开
button1.Enabled:=true;
end;
 
接受答案了.
 
后退
顶部