Before you can programmatically create a report using the Report Generator, you need to define a template file. In order to do this, you can use the following command. This creates a new blank template file using "mlreportgen.dom". Make sure that you only use this command once for each template you create, otherwise it will overwrite your existing template of the same name.
Document.createTemplate('MyReportTemplate','docx');
At this point, if you run your code, you might see the following error:
Error using mlreportgen.dom.DocumentPart/moveToNextHole
Document does not contain a document part template named: Chapter
Error in Untitled2 (line 17)
moveToNextHole(chapterPart);
This error occurs because the "MyReportTemplate.dotx" template file does not have a document part template with the title "Chapter". You will need to open "MyReportTemplate.dotx" in Microsoft word, and then follow the steps at the documentation link below in order to create the "Chapter" template. Please note that the "Automatic Numbering in Word Reports" example specifies the layout of the "Chapter" template.
Best Answer