This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Package: mlreportgen.dom

Fill document holes with generated content





fill(form) fills the holes in a DOM-based form with generated content. Use this method with a class you derive from any of these classes:


Use this method only with derived classes. Invoking this method on an instance of a DOM class causes an error.

This method assumes that the derived class, for each hole in an instance’s template, defines a method having this signature:

HoleId is the ID of a hole defined in the document’s template. d is an instance of the derived class. The fill method moves from the first hole in the document to the last, invoking the corresponding fillHoleId method at each hole. This way, you can define methods that fill the holes without looping. The fill method moves from hole to hole to fill the template.


collapse all

This example shows how to define a report that fills a CustomerName hole in a Word template.

Create a template that has a CustomerName hole. This example assumes that there is a Word template called CustomerLetter.dotx.

In a file, create a report class derived from mlreportgen.dom.Document. From the MATLAB® toolstrip, select New > Class and define the class. For example:

classdef MyReport < mlreportgen.dom.Document
    %MYREPORT defines a customize letter to customers
    % rpt = MyReport('mydoc','docx','CustomerLetter');
    % rpt.CustomerName = 'Smith';
    % fill(rpt);
        function rpt = MyReport(filename,type,template)
          rpt = rpt@mlreportgen.dom.Document(filename,type,template);
        function fillCustomerName(rpt)

Use the report.

rpt = MyReport('mydoc','docx','CustomerLetter');
rpt.CustomerName = 'Mr. Smith';

Input Arguments

collapse all

Form whose holes to fill, specified as a character vector.


In the derived class, define fill methods to insert content for each hole in the template. Use this signature:


HOLE_ID is the ID of a hole defined by the template that the document uses, and docObj is an instance of the derived class. When invoked on a derived Document object, the fill method moves from the first hole in the document to the last, invoking the corresponding fillHOLE_ID method at each hole. This approach eliminates the need for additional code to loop through the holes in a template.

Introduced in R2014b