Main Content

mlreportgen.dom.DOCXPageLayout Class

Namespace: mlreportgen.dom

Page format and layout for section of Microsoft Word document

Description

Use an mlreportgen.dom.DOCXPageLayout object to define the page format, headers, and footers of a section of a Microsoft® Word document.

The mlreportgen.dom.DOCXPageLayout class is a handle class.

Class Attributes

HandleCompatible
true
ConstructOnLoad
true

For information on class attributes, see Class Attributes.

Creation

Description

pageLayoutObj = mlreportgen.dom.DOCXPageLayout creates a DOCXPageLayout object with default property values.

example

Properties

expand all

You can define up to three page headers for a layout, one each for:

  • The first page of the section

  • Even pages

  • Odd pages

You can define up to three page footers for a layout, one each for:

  • The first page of the section

  • Even pages

  • Odd pages

Number of the first page in a section, specified as an integer.

Note

Page numbers are rendered only on mlreportgen.dom.Page objects that you append to the document or to any part of the document. To render page numbers in the page headers or footers, assign an mlreportgen.dom.DOCXPageHeader object to the PageHeaders property or an mlreportgen.dom.DOCXPageFooter object to the PageFooters property. Then append an mlreportgen.dom.Page object to the DOCXPageHeader or DOCXPageFooter object. For example, see Add and Customize Page Numbers in a Microsoft® Word Document. Alternatively, you can append mlreportgen.dom.Page objects to the document itself, or to elements in the document, but the page number renders only on the part of the document where you append the Page object.

Attributes:

NonCopyable
true

Type of page numbering to use, specified as one of the character vectors or string scalars in the table.

ValueMeaningSupported in DOCXSupported in PDF
"a"Lowercase alphabeticYesYes
"A"Uppercase alphabeticYesYes
"i"Lowercase Roman numeralsYesYes
"I"Uppercase Roman numeralsYesYes
"n", "N", "1", "decimal"Arabic numeralsYesYes
"numberInDash"Number with dashes on either sideYesNo
"hebrew1"Hebrew numeralsYesNo
"hebrew2"Hebrew alphabeticYesNo
"arabicAlpha"Arabic alphabeticYesNo
"arabicAbjad"Arabic abjad numeralsYesNo
"thaiLetters"Thai lettersYesNo
"thaiNumbers"Thai numerals YesNo
"thaiCounting"Thai counting systemYesNo

Note

Page numbers are rendered only on mlreportgen.dom.Page objects that you append to the document or to any part of the document. To render page numbers in the page headers or footers, assign an mlreportgen.dom.DOCXPageHeader object to the PageHeaders property or an mlreportgen.dom.DOCXPageFooter object to the PageFooters property. Then append an mlreportgen.dom.Page object to the DOCXPageHeader or DOCXPageFooter object. For example, see Add and Customize Page Numbers in a Microsoft® Word Document. Alternatively, you can append mlreportgen.dom.Page objects to the document itself, or to elements in the document, but the page number renders only on the part of the document where you append the Page object.

Attributes:

NonCopyable
true

Data Types: char | string

Document endnote options, specified as an mlreportgen.dom.EndnoteOptions object. The document uses the default value if any property of EndnoteOptions is empty.

Note

This property overrides the endnote options specified by the document to which this page layout belongs.

Attributes:

NonCopyable
true

Document footnote options, specified as an mlreportgen.dom.FootnoteOptions object. The document uses the default value if any property of FootnoteOptions is empty.

Note

This property overrides the footnote options specified by the document to which this page layout belongs.

Attributes:

NonCopyable
true

Sizes of the margins, header, footer, and gutter for this page layout, specified as an mlreportgen.dom.PageMargins object.

Attributes:

NonCopyable
true

Size of pages in layout, specified as an mlreportgen.dom.PageSize object.

Attributes:

NonCopyable
true

Page borders for layout, specified as an mlreportgen.dom.PageBorder object.

Attributes:

NonCopyable
true

Section break options, specified as one of these character vectors or string scalars:

  • 'Next Page' — Start the section on the next page.

  • 'Same Page' — Start the section on the same page as the current section.

  • 'Odd Page' — Start the section on an odd page.

  • 'Even Page' — Start the section on an even page.

Attributes:

NonCopyable
true

Data Types: char | string

XML markup for unsupported layout formats, specified as a cell array of character vectors or string scalars.

For information about XML markup for Word formats, see https://ecma-international.org/publications-and-standards/standards/ecma-376/.

Attributes:

NonCopyable
true

Data Types: cell | char | string

The class ignores this property.

Attributes:

NonCopyable
true

Format specification for this document element, specified as an array of DOM format objects. Formats that do not apply to this element are ignored.

Attributes:

NonCopyable
true

Custom attributes of this document element, specified as an array of mlreportgen.dom.CustomAttribute objects. The custom attributes must be supported by the output format of the document element to which this object is appended.

Attributes:

NonCopyable
true

Parent of mlreportgen.dom.DOCXPageLayout object, specified as a document element object. A document element must have only one parent.

Attributes:

SetAccess
private
NonCopyable
true

Children of mlreportgen.dom.DOCXPageLayout object, specified as an array of document element objects. This property contains the document element objects appended using the append method.

Attributes:

SetAccess
private
NonCopyable
true

Tag for the mlreportgen.dom.DOCXPageLayout object, specified as a character vector or string scalar. The DOM API generates a session-unique tag as part of the creation of this object. The generated tag has the form CLASS:ID, where CLASS is the object class and ID is the value of the Id property of the object. Specify your own tag value to help you identify where to look when an issue occurs during document generation.

Attributes:

NonCopyable
true

Data Types: char | string

Object identifier for the mlreportgen.dom.DOCXPageLayout object, specified as a character vector or string scalar. The DOM API generates a session-unique identifier when it creates the document element object. You can specify your own value for Id.

Attributes:

NonCopyable
true

Data Types: char | string

Methods

expand all

Examples

collapse all

Use the CurrentPageLayout property of a document to access the layout object for the document. Change the left and right margins of the layout by setting the Left and Right properties of the mlreportgen.dom.PageMargins object used by the layout object.

import mlreportgen.dom.*;
d = Document('mydoc','docx');

open(d);
pageLayoutObject = d.CurrentPageLayout;
pageLayoutObject.PageMargins.Left = '2in';
pageLayoutObject.PageMargins.Right = '2in';
p = Paragraph('Hello World');
append(d,p);

close(d);
rptview(d);

By default, a DOCXPageLayout object specifies a page with an 11-inch height, 8.5-half inch width, and portrait orientation. To change the orientation to landscape, use the rotate method of the DOCXPageLayout object. The method updates the property values of the associated mlreportgen.dom.PageSize object so that the height is 8.5 inches, the width is 11 inches, and the orientation is landscape.

import mlreportgen.dom.*;
d = Document('myreport','docx');
open(d);
 
pageLayoutObj = d.CurrentPageLayout;
rotate(pageLayoutObj);

append(d,'This document has landscape pages');
close(d);
rptview(d);

This example shows how to add and customize page numbers in the footer section of a generated Word document.

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

import mlreportgen.dom.*

Create an mlreportgen.dom.Document object of type DOCX with a title.

document = Document("my_docx_w_page_numbers_document","docx");
heading = Heading(1,"Customize Page Numbers Example");
append(document,heading);

Add content to the document.

append(document,LineBreak);
for pageInd = 1:5
  append(document,sprintf("Content of page number %i",pageInd));
  append(document,PageBreak);
end
append(document,Paragraph("Content of last page"));

Add a page footer to the document by assigning an mlreportgen.dom.DOCXPageFooter object to the PageFooters property of the current page layout. Then set the page number format of the current page layout to uppercase Roman numerals.

curLayout = document.CurrentPageLayout;
curLayout.PageFooters = DOCXPageFooter();
curLayout.PageNumberFormat = "I";

Append an mlreportgen.dom.Page object to the page footer object.

append(curLayout.PageFooters,Page());

Close and view the document.

close(document);
rptview(document);

Version History

Introduced in R2016a