Main Content

Generate a Microsoft Word Document with Page Borders

This example generates a Microsoft Word document that has solid, red, 0.5-point borders positioned 20 points from the page boundary.

pic2a.png

Import the DOM API namespace so that you do not have to use long, fully qualified class names.

import mlreportgen.dom.*;

Create a Word document.

d = Document("myDocument","docx");
open(d);

Create a PageBorder object and specify the border style, color, and width.

pageBorder = PageBorder("solid","red","0.5pt");

Specify that the border position is relative to the page boundary and specify the margin between the page boundary and the border.

pageBorder.MeasureFrom ="pageboundary";
pageBorder.Margin = "20pt";

Set the PageBorder property of the layout associated with the document to the PageBorder object.

d.CurrentPageLayout.PageBorder = pageBorder;

Add text to the document. Close and view the document.

append(d,"The solid, red, 0.5-point border is 20 points from the page boundary.");
close(d);
rptview(d);

See Also

| | | |

Related Topics