此示例显示如何在Word(DOCX)报告中定义页面边距。您可以为DOCX页面定义顶部,底部,左侧,右边缘,以及其标头,页脚和沟槽尺寸。
Import the DOM API packages so you do not have to use long, fully-qualified class names.
importmlreportgen.dom.*;
创建和打开报告。
d = Document('myreport','docx');open(d);
Get the current page layout object.
currentlayout = d.currentpagelayout;
为DOCX文档创建页眉定义。
docxheader.= DOCXPageHeader();
创造一个DOMParagraph
对象并使其中心对齐和粗体。将其字体大小设置为12pt。将它追加到DOCXPageHeader
目的。
p =段落('Sample Traffic Data in Austin');p.Style = [P.Style,{ravign('center'),粗体(true),fontsize('12pt')}]; append(docxheader, p);
Assign the createddocxheader.
object to thePageHeaders
当前页面布局。
currentlayout.pageheaders = docxheader;
Create cell arrays for the styles to be used by the formal table and its table entries.
dataTableStyle = {Border('solid'), ColSep('solid'),Rowsep('solid'), Width('100%')。。。aterermargin('0pt','0pt','0pt','0pt')};
Create some sample data from the Austin traffic camera to include in the table. Then create aFormalTable
对象并包括标题和主体部分中的示例数据。
dataHeader = {'相机ID','Status',“制造商”,'信号工程师区'};dataBody = {'1','TURNED_ON',“光谱”,'东北';'2','TURNED_ON','Sarix','NORTHWEST';'3','关掉','Spectura','SOUTHWEST';'3','TURNED_ON','Spectura','东北';'4','TURNED_ON','Sarix','SOUTHEAST';'5','TURNED_ON',“光谱”,'东北';'6','TURNED_ON','Sarix','NORTHWEST';'7','关掉','Spectura','SOUTHWEST';'8','TURNED_ON','Spectura','东北';'9','TURNED_ON','Sarix','SOUTHEAST'};DataTable =汇编(DataHeader,数据流);DataTable.Header.Style = [DataTable.Header.Style {Bold}];dataTable.Style = [DataTable.Style DataTableBlyyle];附录(D,DataTable);
这Top
财产的财产PageMargins
object specifies the height of the margin. TheHeader
property specifies the distance from the top of the page to the start of the header. The distance from the top of the page to the page body depends on theTop
property,Header
property and the height of the header content. For example, if theHeader
property is less than theTop
property, the header starts in the top margin and expands downward to accommodate the header content. The body begins at the bottom of the margin or the header, which ever is greater.
使用以下设置以确保标题适合Top
margin. Set theTop
property to 1 inch. 1 inch equals 72 points, so 0.25 inches equals 18 pts. Set theHeader
value to 0.75 inches as remaining 0.25 inches is enough to accommodate the 12 ptsParagraph
created in the DOCX Header.
currentLayout.PageMargins.Top ='1in';currentLayout.PageMargins.Header ='0.75in';
为DOCX文档创建页面页脚定义。
docxfooter.= DOCXPageFooter();
Append a horizontal rule to thedocxfooter.
目的。
附加(docxfooter,triconalrule());
将图像附加到docxfooter.
目的。Use the DOMScaleToFit
format to scale the image to fit in the page. Assign the createddocxfooter.
object to thePagefooters.
当前页面布局。。
imgStyle = {ScaleToFit(true), HAlign('正确的'), 高度('0.30in')};img = Image('logo_footer.png');img.Style = imgStyle; append(docxfooter, img); currentLayout.PageFooters = docxfooter;
这Bottom
财产的财产PageMargins
object specifies the height of the page margin. TheFooter
属性指定从页面底部到页脚底部的距离。从页面底部到页面正文的距离取决于Bottom
和Footer
properties and the height of the footer content. For example, if theFooter
property is less than theBottom
property, the footer starts in the bottom margin and expands upward to expand the footer content. The body starts at the top of the margin or the footer, whichever is greater.
Set theBottom
property value to 1 inch. To accommodate the 0.30 highImage
和the horizontal rule created in DOCX Footer, set theFooter
物业价值为0.5英寸。
currentlayout.pagemargins.bottom ='1in';currentlayout.pagemargins.footer =.'0.5in';
This example uses theGutter
setting to leave room on the left side of the page for binding the report。排水沟
尺寸设定为0.25英寸Left
边缘设定为0.5英寸。因此,内容从页面左侧的0.75英寸(左边距+排水沟)开始。这正确的
边缘设定为0.5英寸。
currentLayout.PageMargins.Gutter ='0.25in';currentlayout.pagemargins.left =.'0.5in';currentLayout.PageMargins.Right ='0.5in';
生成并显示报告。
close(d); rptview(d.OutputPath);