Main Content

Fill the Blanks in a Report Form

When you create a form template, you associate an ID with each hole in the template. The ID allows you to navigate the holes in a form, using the DOM moveToNextHole function.

The first time you execute the moveToNextHole function, the DOM API copies to the output document all of the text in the template up to the first hole. At this point, you can start adding content to the output document using the DOM append function, thereby filling in the first hole.

The next time you execute the moveToNextHole function, the DOM API copies all the text between the first and second hole in the template to the output document. You can then fill in the second hole by appending content to the output document. In this way, you generate the output document by copying the content from the template and filling in all its holes.

For example, this function generates a report from a Word template that has holes named Title, Author, and Content. The arguments title, author, and content, are assumed to be character vectors.

function makerpt(title,author,content,rptname,rpttemplate)
      import mlreportgen.dom.*
      rpt = Document(rptname,'docx',rpttemplate);
  
      while ~strcmp(rpt.CurrentHoleId,'#end#')
          switch rpt.CurrentHoleId
               case 'Title'
                   append(rpt,title);
               case 'Author'               
                   append(rpt,author);
               case 'Content'               
                   append(rpt,content);
           end
           moveToNextHole(rpt);
       end
       
      close(rpt);

See Also

Functions

Related Examples

More About