数据导入EXCEL为什么没字段名? (100分)

  • 主题发起人 主题发起人 ljbXS
  • 开始时间 开始时间
L

ljbXS

Unregistered / Unconfirmed
GUEST, unregistred user!
数据导入EXCEL为什么没字段名?
内容有了,字段名没有请大家帮忙[:D][:D][:)]
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;
workbook:olevariant;
worksheet:olevariant;
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;
workbook:olevariant;
worksheet:olevariant;
i,j,a,s,n: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;
i:=1; //EXECL表行号
n:=0;//query字段N序号
j:=1;//EXECL表列号
form23.Query1.First;
for n:=0 to form23.Query1.FieldCount -1 do
begin
worksheet.Cells(i,j):=Query1.fields[n].DisplayLabel;//在EXCEL第一行写上字段名。
j:=j+1;
end;
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;
 
eclApp是什么?
 
我已经修改好了,再试试。如不行,说明原因。
 

Similar threads

I
回复
0
查看
675
import
I
I
回复
0
查看
571
import
I
后退
顶部