MATLAB: How to fill holes in a MS Word Template in Report Generator

fillgeneratorMATLAB Report Generatorreporttemplate

While trying out the Report Generator toolbox, we were wondering if there was a way to fill holes or move between holes from a Microsoft Word template in MATLAB?

Best Answer

Yes, it is possible to both fill and move between holes using Report Generator. There are two main ways to do this: using Report API functions or using DOM API functions.
1) Report API: using "fill" and "customizeReport"
a) Use the "customizeReport" function to create a new subclass of the "Report" superclass.
b) Give it properties matching the "Titles" of the holes in the template
c) Create an instance of the subclass, and assign to the properties the values you want to fill the holes with.
d) Use the "fill" function from the Report API to fill the holes automatically.
For example, if you have a hole in the template called "Name", you can create a subclass called "myReport" with the property "Name". Then, use the following code to fill the hole with a name:
rpt = myReport('outputFilename', 'docx', 'myTemplate')
rpt.Name = "John Smith"
fill(rpt)
You can also fill holes with DOM objects (such as paragraphs or ordered lists) using the same process.
2) DOM API: using "moveToNextHole" and "append"
If you do not need to use Report API objects, you can also create a Document Report Container and use the "moveToNextHole" function. Information about this approach and an example can be found at the following link: