delphi中调用统计函数(300分)

  • 主题发起人 主题发起人 无泪
  • 开始时间 开始时间
try
excel:=createoleobject('excel.application')
except
application.MessageBox('無法打開EXCEL文件,請確認已經安裝了EXCEL','',mb_ok+mb_iconstop);
exit;
end;
excel.visible:=false;
excel.workbooks.add;
// excel.activesheet;
excel.activesheet.pagesetup.orientation:=1;
excel.worksheets[1].pagesetup.topmargin:=2.5;
excel.worksheets[1].pagesetup.bottommargin:=2.5;
excel.worksheets[1].pagesetup.leftmargin:=1.9;
excel.worksheets[1].pagesetup.rightmargin:=1.9 ;
excel.activesheet.cells.borders.item[xlEdgeBottom].Weight:=xlMedium;
excel.worksheets[1].range['A1:O1'].merge(true);
excel.worksheets[1].range['A2:O2'].merge(true);
excel.worksheets[1].cells[1,1].font.name:= '標楷體';
excel.worksheets[1].cells[1,1].font.size:=30;
excel.worksheets[1].cells[1,1].font.bold:=1;
excel.worksheets[1].cells[2,1].font.name:= '標楷體';
excel.worksheets[1].cells[2,1].font.size:=20;
excel.worksheets[1].cells[2,1].font.bold:=1;
excel.worksheets[1].cells[1,1].value:='****有限公司';
excel.worksheets[1].cells[2,1].value:='回港送貨清單 NO:';
excel.worksheets[1].range['a1:a1'].Horizontalalignment:=xlcenter;
excel.worksheets[1].range['a2:a2'].Horizontalalignment:=xlcenter;
excel.worksheets[1].range['a3:d3'].merge(true);
excel.worksheets[1].range['e3:i3'].merge(true);
excel.worksheets[1].range['j3:o3'].merge(true);
excel.worksheets[1].range['A4:O5'].select;
excel.worksheets[1].range['A4:O5'].Horizontalalignment:=xlcenter;;
excel.worksheets[1].range['A4:A5'].select;
excel.worksheets[1].range['A4:A5'].merge;
excel.worksheets[1].cells[4,1].font.name:='標楷體';
excel.worksheets[1].cells[4,1].font.size:=9;
excel.worksheets[1].cells[4,1].font.bold:=1;
excel.worksheets[1].cells[4,1].value:='產品'+#10+'編號';
excel.worksheets[1].range['B4:B5'].select;
excel.worksheets[1].range['B4:B5'].merge;
i:=6;
adoquery2.First;
while not adoquery2.Eofdo
begin
excel.worksheets[1].cells[i,1].font.size:=12;
excel.worksheets[1].cells[i,2].font.size:=12;
excel.worksheets[1].cells[i,3].font.size:=12;
excel.worksheets[1].cells[i,4].font.size:=12;
excel.worksheets[1].cells[i,5].font.size:=12;
excel.worksheets[1].cells[i,6].font.size:=12;
excel.worksheets[1].cells[i,7].font.size:=12;
excel.worksheets[1].cells[i,10].font.size:=12;
excel.worksheets[1].cells[i,11].font.size:=12;
excel.worksheets[1].cells[i,12].font.size:=12;
excel.worksheets[1].cells[i,13].font.size:=12;
excel.worksheets[1].cells[i,14].font.size:=12;
excel.worksheets[1].cells[i,15].font.size:=12;
excel.worksheets[1].cells[i,1].value := adoquery2.fieldbyname('flditemcode').asstring;
excel.worksheets[1].cells[i,2].value := adoquery2.FieldByName('fldcustomerpartsno').AsString;
excel.worksheets[1].cells[i,3].value := adoquery2.FieldByName('fldouterbox').AsString;
excel.worksheets[1].cells[i,4].value := '=E'+inttostr(i)+'/c'+inttostr(i);
excel.worksheets[1].cells[i,5].value := adoquery2.FieldByName('fldqty').AsString;
excel.worksheets[1].cells[i,8].value := adoquery2.FieldByName('fldgrossweight').AsString;
excel.worksheets[1].cells[i,9].value := '=d'+inttostr(i)+'*h'+inttostr(i);
excel.worksheets[1].cells[i,10].value := '=d'+inttostr(i)+'*(h'+inttostr(i)+'-2)';
excel.worksheets[1].cells[i,11].value := adoquery2.FieldByName('fldoutermeasurement1').AsString;
excel.worksheets[1].cells[i,12].value := adoquery2.FieldByName('fldoutermeasurement2').AsString;
excel.worksheets[1].cells[i,13].value := adoquery2.FieldByName('fldoutermeasurement3').AsString;
excel.worksheets[1].cells[i,14].value := '=K'+inttostr(i)+'*L'+inttostr(i)+'*M'+inttostr(i)+'/1000000';
excel.worksheets[1].cells[i,15].value := '=K'+inttostr(i)+'*L'+inttostr(i)+'*M'+inttostr(i)+'*d'+inttostr(i)+'/1000000';
i:=i+1;
adoquery2.Next;
end;
excel.worksheets[1].cells[i,1].value:='合計:';
excel.worksheets[1].cells[i,4].value:='=sum(d6:d'+inttostr(i-1)+')';
excel.worksheets[1].cells[i,9].value:='=sum(I6:I'+inttostr(i-1)+')';
excel.worksheets[1].cells[i,10].value:='=sum(J6:J'+inttostr(i-1)+')';
excel.worksheets[1].cells[i,15].value:='=sum(O6:O'+inttostr(i-1)+')';
excel.worksheets[1].range['a'+inttostr(i+1)+':g'+inttostr(i+1)].merge;
excel.worksheets[1].range['h'+inttostr(i+1)+':o'+inttostr(i+1)].merge;
excel.worksheets[1].cells[i+1,1].value:='麥頭';
excel.worksheets[1].cells[i+1,8].value:='備註';
excel.worksheets[1].range['a'+inttostr(i+2)+':g'+inttostr(i+2)].merge;
excel.worksheets[1].range['h'+inttostr(i+2)+':o'+inttostr(i+2)].merge;
excel.worksheets[1].range['a'+inttostr(i+3)+':g'+inttostr(i+3)].merge;
excel.worksheets[1].range['h'+inttostr(i+3)+':o'+inttostr(i+3)].merge;
excel.worksheets[1].range['a'+inttostr(i+4)+':O'+inttostr(i+4)].merge;
excel.worksheets[1].cells[i+4,1].value:='製表: 復核: 審核:';
str:='O'+inttostr(i+4);str3:='a1';
excel.worksheets[1].range[str3,str].borders.linestyle:=xlcontinuous;
excel.worksheets[1].range[str3,str].borders. weight:=xlthin;
Randomize;
str3:=formatdatetime('yyyyMMdd',now)+'_'+inttostr(random(10000))+'.xls';
savedialog1.FileName:=str3;
savedialog1.DefaultExt:='xls';
savedialog1.Execute;
str3:=savedialog1.FileName;
excel.worksheets[1].saveas(str3);
excel.workbooks.close;
excel.quit;
代碼做了部分處理
http://blog.aicosoft.com/bsmqu
有幾篇關於寫excel的文章,你也可以看一下
 
同志们,怎么没有人回答了???
能不用Excel就不用!
有纯用delphi函数实现的吗?
 
自己顶一下
 
多人接受答案了。
 
后退
顶部