Simplify Filling in Forms
The object-oriented approach allows you to use the DOM fill method
to simplify form-based reporting. The fill method is intended for
instances of classes derived from the mlreportgen.dom.Document or
mlreportgen.dom.DocumentPart class. It
assumes that for each hole in a document or document part template, the derived class
defines a method having this signature:
fillHoleID(obj)
The HoleID part of the signature is the ID of a hole defined by the
document or document part template. The obj argument is an instance
of the derived class. For example, supposed that a template defines a hole named
Author. Then the derived class defines a method name
fillAuthor to fill the Author hole. Assuming
that the derived class defines methods for filling the holes, the
fill method moves from the first hole in the document or part to
the last, invoking the corresponding fillHoleID method to fill each
hole.
The fill method eliminates the need for a report program to loop
explicitly through the holes in a document or document part’s template. The report need
only invoke the document or part fill method. For example, suppose
that you have derived a report class, name MyReport, from the
mlreportgen.dom.Document class and that this derived class defines
methods for each of the holes defined by the report template, based on data supplied in
its constructor. Then, you need only three lines to generate an instance of
MyReport:
function makeReport(rptdata)
rpt = MyReport(rptdata);
fill(rpt);
close(rpt);
For an example of a forms-based, object-oriented report program, in the Examples pane of the MATLAB® Report Generator™ documentation, open the Object-Oriented Report example.