procedure TF_cusorder.Button1Click(Sender: TObject);
var
myexcel:variant;
i,j:integer;
workbook:olevariant;
worksheet:olevariant;
begin
inherited;
try
Screen.Cursor:=crHourGlass;
myexcel:=createoleobject('excel.application');
myexcel.application.workbooks.add;
myexcel.caption:='导入EXCEL';
myexcel.visible:=true;
workbook:=myexcel.Application.workbooks[1];
worksheet:=workbook.worksheets[1];
except
messagedlg('无法启动EXCEL,请确认是否安装',mtinformation,[mbyes],0);
exit;
end;
for j := 0 to dindandqry.FieldCount - 1 do
begin
i:=1;
dindandqry.First;
worksheet.cells[1,j+1]:=DBGrid1.Columns[j].Title.Caption;
while not dindandqry.Eof do
begin
inc(i);
worksheet.cells[i,j+1]:=dindandqry.fields[j].asstring;
dindandqry.Next;
end;
end;
Screen.Cursor:=crDefault;
var
myexcel:variant;
i,j:integer;
workbook:olevariant;
worksheet:olevariant;
begin
inherited;
try
Screen.Cursor:=crHourGlass;
myexcel:=createoleobject('excel.application');
myexcel.application.workbooks.add;
myexcel.caption:='导入EXCEL';
myexcel.visible:=true;
workbook:=myexcel.Application.workbooks[1];
worksheet:=workbook.worksheets[1];
except
messagedlg('无法启动EXCEL,请确认是否安装',mtinformation,[mbyes],0);
exit;
end;
for j := 0 to dindandqry.FieldCount - 1 do
begin
i:=1;
dindandqry.First;
worksheet.cells[1,j+1]:=DBGrid1.Columns[j].Title.Caption;
while not dindandqry.Eof do
begin
inc(i);
worksheet.cells[i,j+1]:=dindandqry.fields[j].asstring;
dindandqry.Next;
end;
end;
Screen.Cursor:=crDefault;
所有评论(0)