User`s guide

13 Create a Report Program
13-132
template-defined headers and footers for the current section of a document or document
part.
The value of the CurrentDOCXSection property is a DOCXSection object whose
PageHeaders and PageFooters properties contain a cell array of DOCXPageHeader
and DOCXPageFooter objects corresponding to the template-defined headers and footers
of the current section. The header cell array can contain as many as three header objects,
depending on how many of the possible types of headers (first page, even page, odd page)
you define for the section. The footers cell array similarly can contain as many as three
footer objects. The objects can appear in any order in the cell array. Thus, to access a
header or footer of a particular type, search the cell array to find the one you want to
access.
Append Content to a Template-Defined Header or Footer
You can use the DOM API to append content to a template-defined header or footer
that appears on every page in a section. To append content to a header or footer in the
current section of a document or document part, first use the document or document part
CurrentDOCXSection property to access the DOCXPagerHeader or DOCXPageFooter
object. Then use the append method of a DOCXPageHeader or DOCXPageFooter object
to append content to the header or footer. Because header and footer objects are a kind
of document part object, you can append any kind of content to a page header or footer
that you can append to a document part, for example, images and tables as well as
paragraphs.
You can use holes in the header and footers of your main template to control the
positioning of content that you append to the headers and footers. For example, this
script appends today's date to a hole named Date on the first template-defined page
header of the first section of a report. This example assumes that the Word template
MyReportTemplate has one section that defines a first page, odd page, and even page
header and footer.
import mlreportgen.dom.*;
d = Document('MyReport','docx','MyReportTemplate');
open(d);
sect = d.CurrentDOCXSection;
for i = 1:numel(sect.PageHeaders)
if strcmpi(sect.PageHeaders(i).PageType,'first')
firstPageHeader = sect.PageHeaders(i);
while ~strcmp(firstPageHeader.CurrentHoleId,'#end#')