[转]Delphi导出Excel的设置操作
procedure CreatRepSheet(SheetName:String;PageSize,PageLay:Integer);
{新建Excel工作簿、进行页面设置}
begin
{新建Excel工作簿}
if ExlApp.WorkBooks.Count < then
begin
ExlBook := ExlApp.Workbooks.Add; //ExlBook:=ExlApp.WorkBooks[].WorkSheets[];
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.
[转]Delphi导出Excel的设置操作的更多相关文章
- Delphi导出Excel的设置操作
procedure CreatRepSheet(SheetName:String;PageSize,PageLay:Integer); {新建Excel工作簿.进行页面设置} begin {新建Exc ...
- NPOI导出EXCEL 打印设置分页及打印标题
在用NPOI导出EXCEL的时候设置分页,在网上有查到用sheet1.SetRowBreak(i)方法,但一直都没有起到作用.经过研究是要设置 sheet1.FitToPage = false; 而 ...
- [转]NPOI导出EXCEL 打印设置分页及打印标题
本文转自:http://www.cnblogs.com/Gyoung/p/4483475.html 在用NPOI导出EXCEL的时候设置分页,在网上有查到用sheet1.SetRowBreak(i)方 ...
- C#+Aspose.Cells 导出Excel及设置样式 (Webform/Winform)
在项目中用到,特此记录下来,Aspose.Cells 不依赖机器装没有装EXCEL都可以导出,很方便.具体可以参考其他 http://www.aspose.com/docs/display/cells ...
- POI操作EXCEL之导出Excel(设置有效性,下拉列表引用)
本人使用的是poi-bin-3.10-FINAL-20140208.zip 版本的poi以下是程序关键代码: //需要引用的类 import java.io.File; import java.io. ...
- C#导出Excel,并且设置Excel单元格格式,合并单元格.
注:要添加COM组件 Microsoft Excel 11.0 Object Library 引用. 具体代码如下: using System; using System.Collections.G ...
- PHP导出Excel,设置表格样式,填充颜色等较为复杂样式
// 注:只是在此做下记录,有兴趣的可以参考,不做实际教程文档 <?php //引入Li类对数据进行操作include_once('./Li.php');//引入Excel类库对对数据进行操作i ...
- 利用PHPExcel导出Excel并设置Excel格式以及数据源
浏览:23969 发布日期:2013/07/24 分类:技术分享 代码有点长,读起来有点累.先来个截图 导出的Excel太宽了,所以将后面的列宽重新调整了再截的图 功能包括: 1.设置单元格格式,包括 ...
- DevExpress导出Excel样式设置
/// <summary> /// 导出到Excel /// </summary> /// <param name="gridControl"> ...
随机推荐
- iOS手写2048--基于Xcode7.1
闲着没事自己想了下,半天写出来了,没有美化,只是实现了基本的2048,被我改成了A.B.C.D.E: 没有游戏开发经验,完全基于uiview 和 一大堆逻辑计算,如果你有指针.链表的使用经验,应该会很 ...
- UIPickerView 地区解析 -- 全国省、市、区 plist 解析 -- 读取UIPickerView 当前显示内容
一个简单的plist 解析过程,借助UIPickerView 实现了手选全国的 省市区 方法, 源码中有详细注释:长句自己可以拆开看,最好的方法是,拆开,并打印,查看每一步打印的结果,结合Plist文 ...
- 蓝牙4.0BLE cc2540 usb-dongle的 SmartRF Packet Sniffer 抓取数据方法
蓝牙4.0的开发, 现在真热火的很, 但是很多朋友买了我们出品的cc2540 usb-dongle后, 都反馈说不知道如何抓包, 并且, 即使很多朋友到TI官网论坛去找信息,不少朋友依然是无功而返,实 ...
- CN消息的来源——父窗口不知道怎么处理,于是把这个消息加上CN_BASE在分发到实际的子窗体
VCL存在一些非API消息以供其内部使用,为什么要这样做呢?这要从WM_COMMAND & WM_NOTIFY消息说起,我们说WM_COMMAND消息并不是直接发给实际产生消息的窗体,而是发送 ...
- 后缀自动机(SAM) :SPOJ LCS - Longest Common Substring
LCS - Longest Common Substring no tags A string is finite sequence of characters over a non-empty f ...
- 将汉字转化为拼音,正则表达式和得到汉字的Unicode编码
一:上图,不清楚的看代码注解,很详细了 二:具体代码 窗体代码 using System; using System.Collections.Generic; using System.Compone ...
- Python 实时日志平台 Sentry
原文地址:http://www.oschina.net/p/sentry Sentry 是一个实时的事件日志和聚合平台,基于 Django 构建. Sentry 可以帮助你将 Python 程序的所有 ...
- bzoj 3876 [Ahoi2014]支线剧情(有上下界的最小费用流)
3876: [Ahoi2014]支线剧情 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 484 Solved: 296[Submit][Status ...
- 控制uwsgi 的信号量
最近在用nginx+uwsgi+djano搭建一个网站,当.py文件修改后,如果不重启uwsgi,修改无法应用. 查了下uwsgi的相关文档 ,找到几个解决方案.顺便翻译下以备查看 启动服务 Star ...
- poj 3084 最小割
题目链接:http://poj.org/problem?id=3084 本题主要在构图上,我采用的是把要保护的房间与源点相连,有intruder的与汇点相连,相对麻烦. #include <cs ...