主要内容

Set Page Margins in a Word Report

此示例显示如何在Word(DOCX)报告中定义页面边距。您可以为DOCX页面定义顶部,底部,左侧,右边缘,以及其标头,页脚和沟槽尺寸。

Create Report

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);

Create DOCX Page Header

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 Body Content

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);

Set Top Margin and Header Size

Top财产的财产PageMarginsobject specifies the height of the margin. TheHeaderproperty 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 theTopproperty,Headerproperty and the height of the header content. For example, if theHeaderproperty is less than theTopproperty, 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.

使用以下设置以确保标题适合Topmargin. Set theTopproperty to 1 inch. 1 inch equals 72 points, so 0.25 inches equals 18 pts. Set theHeadervalue to 0.75 inches as remaining 0.25 inches is enough to accommodate the 12 ptsParagraphcreated in the DOCX Header.

currentLayout.PageMargins.Top ='1in';currentLayout.PageMargins.Header ='0.75in';

Create DOCX Page Footer

为DOCX文档创建页面页脚定义。

docxfooter.= DOCXPageFooter();

Append a horizontal rule to thedocxfooter.目的。

附加(docxfooter,triconalrule());

将图像附加到docxfooter.目的。Use the DOMScaleToFitformat 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;

Set Bottom Margin and Footer Size

Bottom财产的财产PageMarginsobject specifies the height of the page margin. TheFooter属性指定从页面底部到页脚底部的距离。从页面底部到页面正文的距离取决于BottomFooterproperties and the height of the footer content. For example, if theFooterproperty is less than theBottomproperty, 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 theBottomproperty 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';

Set Left Margin, Right Margin and Gutter Size

This example uses theGuttersetting 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);