Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

mlreportgen.dom.Document.fill

Package: mlreportgen.dom

Fill document holes with generated content

Syntax

fill(form)

Description

example

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:

Note

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:

fillHoleId(d)
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.

Examples

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);
    
    properties
        CustomerName;
    end
    
    methods
        function rpt = MyReport(filename,type,template)
          rpt = rpt@mlreportgen.dom.Document(filename,type,template);
        end
        
        function fillCustomerName(rpt)
          append(rpt,rpt.CustomerName);
        end
    end
    
end

Use the report.

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

Input Arguments

collapse all

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

Tips

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

fillHOLE_ID(docObj);

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

Was this topic helpful?