谢谢,程序写得不太好<br>unit NdateSal;<br>interface<br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, GridsEh, DBGridEh, DB, ADODB,comobj,excel2000;<br>type<br> TFrmNdateCal = class(TForm)<br> ADOQuery1: TADOQuery;<br> ADOQuery2: TADOQuery;<br> DataSource1: TDataSource;<br> DBGridEh1: TDBGridEh;<br> Button1: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure FormCreate(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br>var<br> FrmNdateCal: TFrmNdateCal;<br>implementation<br>uses RePublice;<br>{$R *.dfm}<br>procedure TFrmNdateCal.Button1Click(Sender: TObject);<br>var<br> a1,a2,a3,a4,a5,a6,a7,a8,a9,a10:integer;<br> b1,b2,b3,b4,b5,b6,b7,b8,b9,b10:string;<br> c1,c2,c3,c4,c5,c6,c7,c8,c9,c10:integer;<br> myexcel:variant;<br> workbook
levariant;<br> worksheet
levariant;<br> j,k,m:integer;<br>begin<br> ADOQuery1.Active:=False;<br> ADOQuery2.Active:=False;<br> try<br> ADOQuery1.Active:=true;<br> ADOQuery2.Active:=true;<br> ADOQuery1.First;<br> ADOQuery2.First;<br> while not self.ADOQuery1.Eof do<br> begin<br> if (self.ADOQuery1.Fields[8].Value<=10) then<br> begin<br> inc(a1);<br> b1:='10'+StrDay+Stryx;<br> end;<br> if (self.ADOQuery1.Fields[8].Value<=20) and (self.ADOQuery1.Fields[8].Value>10) then<br> begin<br> inc(a2);<br> b2:='10'+StrDay;<br> end;<br> if (self.ADOQuery1.Fields[8].Value<=30) and (self.ADOQuery1.Fields[8].Value>20) then<br> begin<br> inc(a3);<br> b3:='20'+StrDay;<br> end;<br> if (self.ADOQuery1.Fields[8].Value<=40) and (self.ADOQuery1.Fields[8].Value>30) then<br> begin<br> inc(a4);<br> b4:='30'+StrDay;<br> end;<br> if (self.ADOQuery1.Fields[8].Value<=50) and (self.ADOQuery1.Fields[8].Value>40) then<br> begin<br> inc(a5);<br> b5:='40'+StrDay;<br> end;<br> if (self.ADOQuery1.Fields[8].Value<=60) and (self.ADOQuery1.Fields[8].Value>50) then<br> begin<br> inc(a6);<br> b6:='50'+StrDay;<br> end;<br> if (self.ADOQuery1.Fields[8].Value<=70) and (self.ADOQuery1.Fields[8].Value>60) then<br> begin<br> inc(a7);<br> b7:='60'+StrDay;<br> end;<br> if (self.ADOQuery1.Fields[8].Value<=80) and (self.ADOQuery1.Fields[8].Value>70) then<br> begin<br> inc(a8);<br> b8:='70'+StrDay;<br> end;<br> if (self.ADOQuery1.Fields[8].Value<=90) and (self.ADOQuery1.Fields[8].Value>80) then<br> begin<br> inc(a9);<br> b9:='80'+StrDay;<br> end;<br> if (self.ADOQuery1.Fields[8].Value>90) then<br> begin<br> inc(a10);<br> b10:='90'+StrDay+Strys;<br> end;<br> self.ADOQuery1.Next;<br> end;<br>//指定交货日<br> while not self.ADOQuery2.Eof do<br> begin<br> if (self.ADOQuery2.Fields[8].Value<=10) then<br> begin<br> inc(c1);<br> end;<br> if (self.ADOQuery2.Fields[8].Value<=20) and (self.ADOQuery2.Fields[8].Value>10) then<br> begin<br> inc(c2);<br> end;<br> if (self.ADOQuery2.Fields[8].Value<=30) and (self.ADOQuery2.Fields[8].Value>20) then<br> begin<br> inc(c3);<br> end;<br> if (self.ADOQuery2.Fields[8].Value<=40) and (self.ADOQuery2.Fields[8].Value>30) then<br> begin<br> inc(c4);<br> end;<br> if (self.ADOQuery2.Fields[8].Value<=50) and (self.ADOQuery2.Fields[8].Value>40) then<br> begin<br> inc(c5);<br> end;<br> if (self.ADOQuery2.Fields[8].Value<=60) and (self.ADOQuery2.Fields[8].Value>50) then<br> begin<br> inc(c6);<br> end;<br> if (self.ADOQuery2.Fields[8].Value<=70) and (self.ADOQuery2.Fields[8].Value>60) then<br> begin<br> inc(c7);<br> end;<br> if (self.ADOQuery2.Fields[8].Value<=80) and (self.ADOQuery2.Fields[8].Value>70) then<br> begin<br> inc(c8);<br> end;<br> if (self.ADOQuery2.Fields[8].Value<=90) and (self.ADOQuery2.Fields[8].Value>80) then<br> begin<br> inc(c9);<br> end;<br> if (self.ADOQuery2.Fields[8].Value>90) then<br> begin<br> inc(c10);<br> end;<br> self.ADOQuery2.Next;<br> end;<br> begin<br> ADOQuery1.First;<br> try<br> myexcel:=createoleobject('excel.application');<br> myexcel.application.workbooks.add;<br> workbook:=myexcel.application.workbooks[1];<br> worksheet:=workbook.worksheets.item[1];<br> for j:=0 to DBGridEh1.FieldCount-1 do //写表头<br> begin<br> worksheet.cells[1,j+1]:=DBGridEh1.Columns[j].Title.Caption ;<br> end;<br> except<br> showmessage(StrEExportToExcel);<br> end;<br> k:=2;<br> while not ADOQuery1.Eof do<br> begin<br> for j:=0 to ADOQuery1.FieldCount-1 do //写表体<br> begin<br> if ADOQuery1.Fields[j].DataType=ftstring then //判断字段类型<br> worksheet.cells[k,j+1].NumberFormatLocal :='@';<br> worksheet.cells[k,j+1]:=ADOQuery1.Fields[j].AsString;<br> end;<br> inc(k);<br> ADOQuery1.Next;<br> end;<br> end;<br> worksheet:=workbook.worksheets.item[2];<br> m:=1;<br> begin<br> worksheet.cells[1,m]:=StrDate;<br> worksheet.cells[2,m]:=Strhopeday;<br> worksheet.cells[3,m]:=StrEInput;<br> inc(m);<br> worksheet.cells[1,m]:=b1;<br> worksheet.cells[2,m]:=a1;<br> worksheet.cells[3,m]:=c1;<br> inc(m);<br> worksheet.cells[1,m]:=b2;<br> worksheet.cells[2,m]:=a2;<br> worksheet.cells[3,m]:=c2;<br> inc(m);<br> worksheet.cells[1,m]:=b3;<br> worksheet.cells[2,m]:=a3;<br> worksheet.cells[3,m]:=c3;<br> inc(m);<br> worksheet.cells[1,m]:=b4;<br> worksheet.cells[2,m]:=a4;<br> worksheet.cells[3,m]:=c4;<br> inc(m);<br> worksheet.cells[1,m]:=b5;<br> worksheet.cells[2,m]:=a5;<br> worksheet.cells[3,m]:=c5;<br> inc(m);<br> worksheet.cells[1,m]:=b6;<br> worksheet.cells[2,m]:=a6;<br> worksheet.cells[3,m]:=c6;<br> inc(m);<br> worksheet.cells[1,m]:=b7;<br> worksheet.cells[2,m]:=a7;<br> worksheet.cells[3,m]:=c7;<br> inc(m);<br> worksheet.cells[1,m]:=b8;<br> worksheet.cells[2,m]:=a8;<br> worksheet.cells[3,m]:=c8;<br> inc(m);<br> worksheet.cells[1,m]:=b9;<br> worksheet.cells[2,m]:=a9;<br> worksheet.cells[3,m]:=c9;<br> inc(m);<br> worksheet.cells[1,m]:=b10;<br> worksheet.cells[2,m]:=a10;<br> worksheet.cells[3,m]:=c10;<br>************************************************************************<br> myexcel.worksheets[2].Activate;<br> myexcel.ActiveSheet.Range['A1:K3'].Select;<br> myexcel.ActiveChart.Location(xlLocationAsObject,'Sheet2');<br> myexcel.Charts.Add;<br>***********************************************************************<br> end;<br> except<br> showmessage(StrhopedateE);<br> end;<br> self.Close;<br> myexcel.application.visible:=True;<br>end;<br>end.