User`s guide
Create Page Footers and Headers
13-133
switch firstPageHeader.CurrentHoleId
case 'Date'
append(firstPageHeader,date);
end
moveToNextHole(firstPageHeader);
end
break;
end
end
close(d);
rptview(d.OutputPath);
Generate Header and Footer Content That Varies from Page to Page
You cannot programmatically append to headers and footers content that varies from
page to page, such as page numbers or running heads. To create content that varies, use
Word fields, which enable automatic content generation. For example, to include a page
number on each page of a section of your report, insert a page number field in the report
template in the page footer of a section. For more information, see the Microsoft Word
documentation.
Create Page Headers and Footers Programmatically
Perform these steps to create programmatically a page header or footer in the current
section of a report.
1
Use the DOCXPageHeader or DOCXPageFooter constructor to create a page header
or footer of the desired type (first page, odd page, even page, or odd and even page)
based on a template that defines template form (the fixed content and holes for
variable content).
2
Fill the holes in the header or footer with content.
3
Insert the header or footer in the array of page headers or footers of the current
DOCXSection object.
This script creates a first page header from a template stored in the document part
template library of a report.
import mlreportgen.dom.*;
d = Document('MyReport','docx','MyReportTemplate');
open(d);