L
ljbXS
Unregistered / Unconfirmed
GUEST, unregistred user!
数据导入EXCEL为什么没字段名?
内容有了,字段名没有请大家帮忙[][][]
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, Buttons, StdCtrls, ExtCtrls, DB, DBTables,Excel2000,OleServer,ComObj,
Grids, DBGrids, DBCtrls;
procedure TForm22.SpeedButton2Click(Sender: TObject);
var
myexcel:variant;
workbooklevariant;
worksheetlevariant;
i,j,a,s:integer;
begin
try
myexcel:=createoleobject('excel.application');
myexcel.application.workbooks.add;
//myexcel.caption:=edit6.Text;
myexcel.application.visible:=true;
workbook:=myexcel.application.workbooks[1];
worksheet:=workbook.worksheets.item[1];
except
showmessage('EXCEL不存在!');
end;
worksheet.cells[1,dbgrid1.FieldCount]:=form23.query1.fields[j].asstring;
i:=1;
form23.query1.first;
while not form23.query1.eof do
begin
inc(i);
for j:=0 to form23.query1.fieldcount-1 do
worksheet.cells[i,j+1]:=form23.query1.fields[j].asstring;
form23.query1.next;
end;
end;
内容有了,字段名没有请大家帮忙[][][]
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, Buttons, StdCtrls, ExtCtrls, DB, DBTables,Excel2000,OleServer,ComObj,
Grids, DBGrids, DBCtrls;
procedure TForm22.SpeedButton2Click(Sender: TObject);
var
myexcel:variant;
workbooklevariant;
worksheetlevariant;
i,j,a,s:integer;
begin
try
myexcel:=createoleobject('excel.application');
myexcel.application.workbooks.add;
//myexcel.caption:=edit6.Text;
myexcel.application.visible:=true;
workbook:=myexcel.application.workbooks[1];
worksheet:=workbook.worksheets.item[1];
except
showmessage('EXCEL不存在!');
end;
worksheet.cells[1,dbgrid1.FieldCount]:=form23.query1.fields[j].asstring;
i:=1;
form23.query1.first;
while not form23.query1.eof do
begin
inc(i);
for j:=0 to form23.query1.fieldcount-1 do
worksheet.cells[i,j+1]:=form23.query1.fields[j].asstring;
form23.query1.next;
end;
end;