uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, Buttons, StdCtrls, ExtCtrls, DB, DBTables,Excel2000,OleServer,ComObj,
Grids, DBGrids, DBCtrls;
var
myexcel:variant;
workbook
levariant;
worksheet
levariant;
begin
try
myexcel:=createoleobject('excel.application');
myexcel.application.workbooks.add;
myexcel.caption:=q+'至'+w+'客情预订表';
myexcel.application.visible:=true;
workbook:=myexcel.application.workbooks[1];
worksheet:=workbook.worksheets.item[1];
except
showmessage('EXCEL不存在!');
end;
i:=1;
j:=4;
if q<>w then
worksheet.Cells(i,j):=q+'至'+w+'客情预订表'
else
worksheet.Cells(i,j):=q+'客情预订表';
i:=2; //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):=form23.Query1.fields[n].DisplayLabel;
j:=j+1;
end;
i:=2; //EXECL表行号
n:=0;//query字段N序号
i:=2;//EXECL表行号
i:=2;
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;