资源描述:
《delphi控制excel大全(完全版).doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、下面是我写的通用文档微机管理系统的打印部分原代码,包括合并execl单元格,加入分页符号,设置行高,列宽,设置execl页头,设置每页记录数,画单元格边框,调用execl模板等等procedureTfrmMain.Button3Click(Sender:TObject);//动态打印excel报表var tiaojian:string;//tiaojian为一个sql查询语句,全宗号,目录号,起始日期为一数据库字段 begin tiaojian:='; ifEdit7.Text<>'then begin tiaojian:=tiaoji
2、an+'(全宗号='+EDit7.Text+')and'; end; ifEdit8.Text<>'then begin tiaojian:=tiaojian+'(目录号='+Edit8.Text+')and'; end; ifEdit9.Text<>'then begin tiaojian:=tiaojian+'(起始日期>='+Edit9.Text+')and'; end elsetiaojian:=tiaojian+'(起始日期>=0)and'; ifEdit10.Text<>'then begin tiaoj
3、ian:=tiaojian+'(起始日期<='+Edit10.Text+')and'; end; tiaojian:=copy(tiaojian,1,length(tiaojian)-3);//tiaojian为一个sql查询语句 Printanjuan(tiaojian);//调用打印过程 ShellExecute(Handle,'Open',PChar(GetCurpath+'temp.xls'),nil,nil,sw_shownormal);//调用excel查看生成的文件 ProgressBar1.Position:=0;//Progre
4、ssBar1为一个进程条控件end;procedureTfrmMain.Printanjuan(tiaojiao:string);var nowhangi,i,jilushu,LCID:integer;//nowhangi当前execl的所在行,jilushu当前的记录位置 ssql,PathName:string; oldcur:tcursor; ExcelApplication1:TExcelApplication; ExcelWorkbook1:TExcelWorkbook; ExcelWorkSheet1:TExcelWorkshee
5、t; xl,Cell1:olevariant;begin LCID:=LOCALE_USER_DEFAULT; ifFileExists(GetCurpath+'temp.xls')then//删除动态生成的临时temp.xls文件 try DeleteFile(GetCurpath+'temp.xls'); except end; ssql:=';//执行sql查询 ssql:='select*frommainanjuanwhere('+tiaojiao+')orderby系统编号'; doadosql(dm1.queryanj
6、uan,ssql); begin try ExcelApplication1:=TExcelApplication.Create(Self); ExcelWorkbook1:=TExcelWorkbook.Create(Self); ExcelWorkSheet1:=TExcelWorksheet.Create(Self); except showmessage('对不起,您没有安装Excel2000!'); abort; end; end; ExcelApplication1.C
7、onnect; ExcelApplication1.Workbooks.Add(null,0); //如果调用一个模板,改动该句如: //ExcelApplication1.Workbooks.Add('c:zichang.xls',0); ExcelWorkBook1.ConnectTo(ExcelApplication1.Workbooks[1]); ExcelWorkSheet1.ConnectTo(ExcelWorkBook1.Sheets[1]as_WorkSheet); //写入execl ProgressBar1.Posi
8、tion:=5; ifdm1.queryanjuan.RecordCount>