How to fill in header/footer holes in a Word template using Report API without chapters
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am using the mlreportgen.report API to generate a report based off of a Word template. I can fill in holes in the body of the document by creating a subclass of mlreportgen.report.Report using customizeReport(), giving it properties with the same names as the holes in the document, and using the fill() method on the subclass. However, this doesn't work for header/footer holes, they just don't get filled in by fill().
The only documentation I can find for filling in header/footer holes using a Word template uses the DOM API, not the Report API. It describes going into the Document object and finding a DOCXPageHeader, then using moveToNextHole() and append() to fill in the holes. I know that the Report class does have a Document property, and inside there I can find the DOCXPageHeader object, so I would think that I can use moveToNextHole() and append() to edit the header, but the CurrentHoleId is stuck at #end#, even though I just opened the report (see image below). My understanding is that moveToNextHole() doesn't work if the CurrentHoleId is at #end#, so it looks like I can use this.
I am using the same header/footer across the entire document.
So, to reiterate, if I'm using the Report API and a Word template, how can I fill in holes in the header/footers?
0 Kommentare
Antworten (1)
Harshit Gupta
am 10 Okt. 2023
Hi,
I understand your requirement to fill in header and footer holes in a MATLAB Report generated using a Word Template. However, in your case, since the header and footer are the same throughout the document, there is no need to use header and footer holes in the Word Template.
Instead, you can achieve the desired outcome by creating a customChapter with your custom header and footers, and then adding the chapter to your report. The process for adding a custom header and footer to a Word template is similar to that for a PDF template, but with some variations.
Here are the steps to follow:
1.Create the custom Chapter object
>> mlreportgen.report.Chapter.customizeReporter('@customChapter');
2. Navigate to the Word template at "@customChapter/resources/templates/docx/default.dotx". Right-click the DOTX file, and select "Open Outside MATLAB".
3. In Word, go to the Insert tab and select "Quick Parts" > "Section 1". This inserts the template part that's used for chapters.
4.Double-click the header area in the Word document to modify the header and footer as required. Ensure that the "Different First Page" option is unchecked if you want the content to be displayed on all pages of the chapter. Make changes to both the first page and subsequent pages if necessary.
To add a hole to a template, refer to this documentaion for detailed instructions :
5. After editing the header/footer content, double-click the main body of the document to stop editing the header/footer.
6. Update the chapter template part with the new content. Select everything on the page with "Ctrl+A". In the Insert tab, go to "Quick Parts" > "Save Selection to Quick Part Gallery". Set the Name field to "Section1" and the Category to "mlreportgen", then click "OK". Confirm the redefining building block entry if prompted.
8. Delete the content from the main template body by selecting everything with "Ctrl+A" and pressing backspace. Save and close the template.
9. Follow the remaining steps mentioned in the MATLAB Answer post, specifically step 5 and step 6. If you have added any holes, modify the "customChapter.m" class to include properties with matching hole names.
Hope this helps.
Regards,
Harshit
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!