procedure CreatRepSheet(SheetName:String;PageSize,PageLay:Integer);
{新建Excel工作簿、进行页面设置}
begin
{新建Excel工作簿}
if ExlApp.WorkBooks.Count < then
begin
ExlBook := ExlApp.Workbooks.Add; //ExlBook:=ExlApp.WorkBooks[1].WorkSheets[1];
ExlApp.ActiveSheet.Name:=SheetName;
end; {if} {进行页面设置} 以上是怎么不用空间而调用EXCEL的, 很方便的!
//设置页面
if PageSize= then
ExlApp.ActiveSheet.PageSetup.PaperSize := xlPaperA3; //纸张大小: A3
if PageSize= then
ExlApp.ActiveSheet.PageSetup.PaperSize := xlPaperA4; //纸张大小: A4
if PageSize= then
ExlApp.ActiveSheet.PageSetup.PaperSize := xlPaperB5; //纸张大小: B5
if PageLay= then
ExlApp.ActiveSheet.PageSetup.Orientation := xlportrait; //页面放置方向:纵向
if PageLay= then
ExlApp.ActiveSheet.PageSetup.Orientation := xlLandscape; //页面放置方向:横向 //设置页宽自动适应
ExlApp.ActiveSheet.PageSetup.Zoom := False;
ExlApp.ActiveSheet.PageSetup.FitToPagesWide := ;
ExlApp.ActiveSheet.PageSetup.FitToPagesTall := False; //设置页眉、页脚(即:页标题、页号)
ExlApp.ActiveSheet.PageSetup.RightFooter := '打印时间: ' + '&D &T';
ExlApp.ActiveSheet.PageSetup.CenterFooter := '第&''&P&''页,共&''&N&''页'; //设置页边距:
ExlApp.ActiveSheet.PageSetup.TopMargin := 1.5/0.035;
ExlApp.ActiveSheet.PageSetup.BottomMargin := 1.5/0.035;
ExlApp.ActiveSheet.PageSetup.LeftMargin := /0.035;
ExlApp.ActiveSheet.PageSetup.RightMargin := /0.035;
ExlApp.ActiveSheet.PageSetup.HeaderMargin:= 0.5/0.035;
ExlApp.ActiveSheet.PageSetup.FooterMargin := 0.5/0.035; //设置页面对齐方式
ExlApp.ActiveSheet.PageSetup.CenterHorizontally := True; //页面水平居中
//ExlApp.ActiveSheet.PageSetup.CenterVertically := True; //页面垂直居中 //设置整体字体格式
ExlApp.Cells.Font.Name := '宋体'; //字体
ExlApp.Cells.Font.Size := ; //字号
ExlApp.Cells.RowHeight := ; //行高
ExlApp.Cells.VerticalAlignment := ; //垂直方向对齐方式:居中
end; {CreatRepSheet} procedure SetAddMess(H_Mess1,H_Mess2,H_Mess3,F_Mess1,F_Mess2,F_Mess3:String); //用户自定义页眉、页脚(即:页标题、页号) begin ExlApp.ActiveSheet.PageSetup.LeftHeader:=H_Mess1; ExlApp.ActiveSheet.PageSetup.CenterHeader:=H_Mess2; ExlApp.ActiveSheet.PageSetup.RightHeader:=H_Mess3; end;{SetAddMess} procedure SetRepBody(x,ch:Integer;cw:Double;cf:String); //设置整体各列数据格式 begin ExlApp.ActiveSheet.Columns[x].ColumnWidth:=cw; //列宽 ExlApp.ActiveSheet.Columns[x].NumberFormat:=Cf; //单元格数据格式 ExlApp.ActiveSheet.Columns[x].HorizontalAlignment:=ch; //水平方向对齐方式 end;{SetRepBody} procedure CreatTitle(TitleName:String;y:Integer); {设置标题} Var RepSpace:String; begin CellMerge(,,,y); ExlApp.cells(,):=TitleName; RepSpace:='A1'+':'+GetRepRange(,y); ExlApp.Range[RepSpace].Select; ExlApp.Selection.NumberFormat :='G/通用格式'; ExlApp.Selection.Font.Size:=; ExlApp.Selection.Font.Name:='黑体'; ExlApp.Selection.Font.Bold:=True; ExlApp.Selection.HorizontalAlignment:=; //水平方向对齐方式:居中 ExlApp.Rows[].RowHeight:=; end;{RepHead} procedure CreatSubHead(SubTitle: Array of String); {设置常规子表头} Var i,j:Integer; begin j:=; for i:=Low(SubTitle) to High(SubTitle) do begin Inc(j); ExlApp.cells(,j):=SubTitle[i]; end; end;{CreatRepHead} procedure SubHeadFormat(y,r:Integer); {设置子表头格式} Var RepSpace:String; n:Integer; begin RepSpace:='A2'+':'+GetRepRange(+r,y); ExlApp.Range[RepSpace].Select; ExlApp.Selection.NumberFormat :='G/通用格式'; ExlApp.Selection.HorizontalAlignment:=; //表头水平对齐方式:居中 ExlApp.Selection.Font.Bold:=True; for n:= to r do begin ExlApp.Rows[+n].RowHeight:=; SetRepLine(+n,y); end;{for} end;{SubHeadFormat} procedure DTSubHeadGS(x,y,r:Integer); {设置动态子表头格式} Var RepSpace:String; n:Integer; begin RepSpace:=GetRepRange(x,)+':'+GetRepRange(x+r-,y); ExlApp.Range[RepSpace].Select; ExlApp.Selection.NumberFormat :='G/通用格式'; ExlApp.Selection.HorizontalAlignment:=; //表头水平对齐方式:居中 ExlApp.Selection.Font.Bold:=True; for n:= to r- do begin ExlApp.Rows[x+n].RowHeight:=; SetRepLine(x+n,y); end;{for} end;{DTSubHeadGS} procedure WriteData(RepData: String; x,y,flag:Integer); //写入数据 {写数据} begin if flag= then ExlApp.cells(x,y):=StrToDate(RepData) else ExlApp.cells(x,y):=RepData; end;{WriteDate} procedure RepPageBreak(x,y,r:Integer); //X:分页处行数,Y:列数,R:子表头总共的行数 //分页、复制表头 Var RepSpace:String; n:Integer; begin ExlApp.ActiveSheet.Rows[x].PageBreak := ; RepSpace:='A1'+':'+GetRepRange(r+,y); ExlApp.ActiveSheet.Range[RepSpace].Copy; RepSpace:='A'+IntToStr(x); ExlApp.ActiveSheet.Range[RepSpace].PasteSpecial; ExlApp.Rows[x].RowHeight:=; for n:= to r do ExlApp.Rows[x+n].RowHeight:=; end;{RepPageBreak} procedure RepSaveAs(FileName:String); {保存为*.xls文件} begin try ExlBook.saveas(FileName); except MessageDlg('不能访问文件,请关闭Microsoft Excel后再运行本程序!', mtError, [mbOk], ); end; end;{RepSaveAs} procedure RepPrivew(FileName:String); {预览} begin RepCreat; ExlApp.Visible :=True; try ExlApp.workBooks.Open(FileName); ExlApp.Workbooks[].WorkSheets[].PrintPreview; finally ExlApp.Quit; ExlApp:=Unassigned; //ExlApp:=''; end;{try} end;{RepPrivew} procedure RepQuit; {退出Excel} begin ExlBook.Close; ExlApp.Quit; //退出Excel Application ExlApp:=Unassigned; //释放VARIANT变量 end;{RepQuit} procedure RepDestroy; {非正常退出Excel} begin if Not VarIsEmpty(ExlApp) then RepQuit; end;{RepDestroy} end.

最新文章

  1. PHP实现实现数字补零格式化
  2. 使用git删除远程仓库文件
  3. Elasticsearch-PHP 索引操作(转)
  4. 转 Delphi Invalidate的用法
  5. C基础--初学指针
  6. function和感叹号,运算符号的转化
  7. [转载]iOS开发:获取设备信息
  8. wordpress显示多个分类的文章
  9. jsp 页面取值
  10. UVALive 2678 大于s的最短子序列和
  11. [原创]InnoDB体系结构
  12. Xamarin Android Fragment的两种加载方式
  13. 网络1712--c语言嵌套循环作业总结
  14. 禁止WPS2019开机自启动
  15. 5.15 pymysql 模块
  16. SENG201 (Software Engineering I) Project
  17. [JUC-1]并发包实现及线程状态
  18. Confluence 6 代理和 HTTPS 详细配置指南链接
  19. js == 与 === 的区别[转]
  20. BootStrap table隐藏列两种方式 (踩坑)

热门文章

  1. 面试复习题(二)JavaSE高级(未完成)
  2. vs code 保存显示无法写入文件的解决方法
  3. Mongodb数据模型
  4. CH5104 I-country[线性DP+分类讨论]
  5. WDigest
  6. printf计算参数是从右到左压栈的(a++和++a的压栈的区别)
  7. maven项目创建3 (依赖版本冲突)
  8. TTTTTTTTTTTT CF 653D 送邮递员
  9. 导数与微分简单总结(updated)
  10. R_Studio(学生成绩)对数值型数据进行统计量分析