Fill document holes with generated content
fill( 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:
HoleIdis the ID of a hole defined in the document’s template.
dis an instance of the derived class. The fill method moves from the first hole in the document to the last, invoking the corresponding
fillHoleIdmethod 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.
form— Form to fill
Form whose holes to fill, specified as a character vector.
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
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 = email@example.com.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);
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
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.