begin
//数据写入Execl的方法
try
ExcelApplication1 := TExcelApplication.Create(Application);
ExcelWorksheet1 := TExcelWorksheet.Create(Application);
ExcelWorkbook1 := TExcelWorkbook.Create(Application);
ExcelApplication1.Connect;
except
Application.Messagebox('Excel 没有安装!', 'Hello', MB_ICONERROR + mb_Ok);
Exit;
end;
try
excelapplication1.Visible [0]:=true;
ExcelApplication1.Workbooks.Add(EmptyParam, 0);
ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Worksheets[1] as _worksheet);
with excelworksheet1.Cellsdo
begin
Item[1,1]:=userinfo.name+'收费统计报表';
item[2,1]:='收费日期:'+formatdatetime('yyyy-mm-dd',date);
Item[3,1]:='';
Columns.NumberFormatLocal:='@';
with catvdatamodule.QueryPublicdo
begin
close;
sql.clear;
strSQL:='';
strSQL:='select distinct TollType from toll where sfdate='''+formatdatetime('yyyy-mm-dd',Date)+''' order by tolltype';
sql.Add(strSQL);
open;
if not eof then
begin
iCount:=recordcount;
setlength(TollName,recordcount);
for i:=1 to recordcountdo
begin
Item[3,1+i]:=fieldbyname('tolltype').AsString ;
TollName[i-1]:=fieldbyname('tolltype').AsString ;
next;
end;
for i:=1 to iCountdo
begin
close;
sql.clear;
strSQL:='';
strSQL:='select sum(tollmoney) as tol from toll where sfdate='''+formatdatetime('yyyy-mm-dd',Date)+''' and tolltype='''+TollName[i-1]+''' ';
sql.Add(strSQL);
open;
Item[4,1+i]:=fieldbyname('tol').AsString ;
next;
end;
end;
end;
end;
finally
ExcelApplication1.Disconnect;
//ExcelApplication1.Quit;
ExcelApplication1.Free;
ExcelWorksheet1.Free;
ExcelWorkbook1.Free;
end;