Having issues appending text to the header on a DOCX Report
4 views (last 30 days)
I have a DOTX template where I've inserted multiple holes in the body of the template that I've been able to successfully access and append to programmatically using the DOM API but I have not had the same luck with holes within the header of the template.
I've been attempting to access the headers using slreportgen.report.Report.CurrentPageLayout.PageHeaders. This results in a DOXPageHeader with the following properties:
DOCXPageHeader with properties:
Children: [1×4 mlreportgen.dom.TemplateText]
In the template, I've inserted 2 holes in the header but on the output above, it appears to ignore them and go straight to #end#.
The body of my template is broken up into the following holes:
I've noticed that under hole #sect3#, its PageHeader actually starts at hole #start#, but when I move to the next hole, it goes to #end#.
I have also attempted the few examples I've found and also have not been successful appending the a header programmatically...
In summary, the issues I'm having is accessing the holes I've inserted into my DOTX template file.
Anmol Dhiman on 9 Dec 2020
Holes in a header can be accessed from the current DOCX section. You can use the following to access the first section's header information:
d = mlreportgen.dom.Document('mydoc','docx','WordTemplate.dotx');
docHeaders = d.CurrentDOCXSection.PageHeaders;
The "docHeaders" will be an array of headers with "PageType" properties of "first", "default", or "even". Descriptions of what these types mean are at the following link:
You can select the header for the page type you would like and then use the "moveToNextHole" method to progress through the holes in the header:
docHead1 = docHeaders(1);
holeId = docHead1.moveToNextHole;
You can also move through the holes in the main body of the section with the following:
nextHoleID = d.moveToNextHole;
If the document has multiple sections, then as you progress through the holes in the document, you will encounter holes with ID's like "#sect<x>#", where "<x>" is the section number. Once the "CurrentHoleId" of the document has this ID, then you can access the headers of the new section in the same way as above using "d.CurrentDOCXSection".
Footers can also be accessed with a similar method
docFooters = d.CurrentDOCXSection.PageFooters;
Hope it Helps