转帖 uses ComObj procedure Tfrom1.button1.click(sender:object); var myexcel:variant; workbook:olevariant; worksheet:olevariant; i,j:integer; begin try myexcel:=createoleobject('excel.application'); myexcel.application.wordbooks.add; myexcel.caption:='将数据导入到EXCEL表中'; myexcel.application.visible:=true; workbook:=myexcelobject1.application.workbooks[1]; wordsheet:=wordbook.wordsheets.item[1]; except showmessage('EXCEL不存在!'); end; i:=0; table1.first; while not table1.eof do begin inc(i); for j:=0 to table1.fieldcount-1 do wordsheet.cells[i,j+1]:=table1.fields[j].asstring; table1.next; end; end;
uses ComObj
procedure Tfrom1.button1.click(sender:object);
var
myexcel:variant;
workbook:olevariant;
worksheet:olevariant;
i,j:integer;
begin
try
myexcel:=createoleobject('excel.application');
myexcel.application.wordbooks.add;
myexcel.caption:='将数据导入到EXCEL表中';
myexcel.application.visible:=true;
workbook:=myexcelobject1.application.workbooks[1];
wordsheet:=wordbook.wordsheets.item[1];
except
showmessage('EXCEL不存在!');
end;
i:=0;
table1.first;
while not table1.eof do
begin
inc(i);
for j:=0 to table1.fieldcount-1 do
wordsheet.cells[i,j+1]:=table1.fields[j].asstring;
table1.next;
end;
end;