what are reporters?
reporters are matlab® objects that generate formatted content when added to a matlab report generator™ report object. matlab report generator provides reporters for generating common report components, such as title pages, tables of contents, chapters, subsections, figures, and matlab variables values. you can customize the content and appearance of these reporters. you can also create your own reporters. for a list of built-in report api objects, enter this matlab command:
help mlreportgen.report
reporters and dom objects
in addition to reporters, matlab report generator provides another set of objects for generating report content. these objects are document object model (dom) objects. they implement a model of a document used by html, word, and other document creation software. the model defines a document as a hierarchy of objects commonly found in documents, such as text strings, paragraphs, images, and tables. the dom api contains software objects that generate these basic document objects. for a list of the dom objects, enter this matlab command:
help mlreportgen.dom
reporters, by contrast, create high-level document structures, such as title pages, tables of contents and chapters, that occur in many, but not all types of documents. the advantage of reporters is that a single reporter can create content that would require many dom objects. however, a report generator program typically requires both dom and reporter objects. for example, a chapter reporter generates the title and page layout of a report chapter, but not its content. the dom api provides text, paragraph, table, list, image, and other objects that you can use to create reporter content.
the following matlab program illustrates using both reporters and dom objects to
create a pdf report. the program uses a dom text
object to add a
block of text to the chapter. all other objects in this example
(report
, titlepage
,
tableofcontents
, and chapter
) are reporter objects.
rpt = mlreportgen.report.report('myreport','pdf'); append(rpt,mlreportgen.report.titlepage('title','my report',... 'author','myself')) append(rpt,mlreportgen.report.tableofcontents) ch = mlreportgen.report.chapter('title','sample text'); append(ch,mlreportgen.dom.text... ('here is sample text using a dom text object.')) append(rpt,ch) close(rpt) rptview(rpt)
reporter elements
a reporter typically includes the following elements:
template documents that define the appearance, fixed content, and holes for dynamic content generated by the reporter. a reporter typically provides a set of templates files, one for each supported output type: word, pdf, and html. each template file contains a library of templates used by the reporter to format its content. for example, the report api
titlepage
reporter uses a template namedtitlepage
to format a title page. thetitlepage
template is stored in the template libraries of its template files. you can modify this template to rearrange or add content to a title page. for information, see templates.properties that specify the dynamic content generated by the reporter. these properties correspond to holes in the reporter template. a reporter fills the template holes with the values of the corresponding properties.
matlab class that defines the reporter properties and methods you use to create and manipulate the reporter. reporter class names begin with the prefix,
mlreportgen.report
. for example, the title page reporter ismlreportgen.report.titlepage
. you can omit the prefix in a matlab script or function by inserting this statement at the beginning of the script or function:likewise, you can includeimport mlreportgen.report.*
import mlreportgen.dom.*
to use short dom class names.constructor method that creates a reporter object as an instance of the reporter class. the name of the constructor is the same as the name of the class.
dom object that contains the content generated by the report. this object is referred to as the implementation of the reporter. each reporter has a
getimpl
method that creates the implementation object, which is typically a domdocumentpart
object.
using reporters in a matlab program
to generate content in a report program, follow these steps:
the example program described in these steps creates a simple document that includes only a title page. however, the steps demonstrate the tasks to create a full report. the full program listing is shown after the step descriptions.
create a report object
create a report object (mlreportgen.report.report
) to contain
the content generated by the report. the report object uses a dom
document
object to hold content generated by reporters added
to the report. this code imports the report api package, which enables the code
to use short class names. then, it creates a pdf report object
(rpt
).
import mlreportgen.report.* rpt = report('myreport','pdf');
create an instance of the reporter
create an instance of the reporter class, that is, instantiate the reporter,
using its constructor. the constructor can also set the properties of the
reporter object it creates. for example, this code creates a title page reporter
(tp
) and sets its title
and
author
properties.
tp = titlepage('title','my report','author','john smith');
set the properties of an existing reporter
to set reporter properties after a program has created a reporter, the program
can use matlab dot notation. for example, this code sets the
subtitle
and pubdate
properties of
a titlepage
reporter (tp
).
tp.subtitle = 'on my project'; tp.pubdate = date;
add the reporter to a report
to generate content using a reporter, a report program must add the reporter
to the report object, using the append
method of the report
object. the append
method works by invoking the
getimpl
method of that reporter. the
getimpl
method creates the implementation of the reporter.
then, the append
method adds the implementation to the dom
document
object that serves as the implementation of the
report object. you can also use the append
method to add dom
objects to the report. you cannot, however, add another dom
document
to a report.
for example, this code adds the title page reporter (tp
) to
the report
(rpt
).
append(rpt,tp)
close the report object
when a report program has finished adding content to a report, it must close
the report, using the close
method of the report object.
closing a report writes the report content to a document file of the type, such
as pdf, specified by the constructor of the report object.
close(rpt)
this code is the complete program for the report, which includes only a title page.
import mlreportgen.report.* rpt = report('myreport','pdf'); tp = titlepage('title','my report',... 'author','john smith'); tp.subtitle = 'on my project'; tp.pubdate = date; append(rpt,tp) close(rpt) rptview(rpt)
see also
| | |