Create Report Programs
The MATLAB® Report Generator™ includes classes that allow you to create report generator programs. These programs can generate Microsoft® Word, HTML, and PDF reports. The programs must include certain items and can include some optional items, both of which are listed here and described at each associated link. For information on Report API and how it compares to the Document Object Model (DOM), see What Are Reporters?
Required Report Program Tasks and Elements
All report generator programs must:
Create a report container. See Create Report Containers.
Create and add content to the container. See Add Content to Reports and Content Generation. The content can be
Report API Reporters
DOM API objects
MATLAB objects (doubles, cell arrays, MATLAB tables, strings, and so on)
Close the report container. See Close Reports.
Optional Report Program Tasks and Elements
Optionally, in report generator programs, you:
Import Report API classes, which enables using non-fully qualified Report API class names, for example,
TitlePage
, instead ofmlreportgen.report.TitlePage
. See Import API namespaces.Import DOM API classes, if the program adds DOM objects to the report, which enables using non-fully qualified DOM API class names.
Configure reporters by setting their property values. See Content Generation.
Add content to reporters by using the
add
method.Note
The only reporters you can both configure and add content to are the
Section
andChapter
reporters. TheChapter
reporter is a subclass of theSection
reporter.Display the report to see the generated report output. See Display Reports.
Display report progress messages to monitor report progress. See Display Progress and Debugger Messages.
Generate and Display a PDF Report Programmatically
This example shows how to generate and display a PDF report using the Report API.
1. Import report API classes.
import mlreportgen.report.*
2. Add a report container.
rpt = Report("output","pdf");
3. Add title page and table of contents reporters to the container.
titlepg = TitlePage; titlepg.Title = "My Airplane"; titlepg.Author = "Pilot A"; add(rpt,titlepg); add(rpt,TableOfContents);
4. Add a chapter that contains text and images to the report.
chap = Chapter("Plane Image"); add(chap,"Here is the plane:"); add(chap,FormalImage("Image","b747.jpg", ... "Height","5in","Width","5in", ... "Caption","Boeing 747")); add(rpt,chap);
5. Close the report.
close(rpt);
6. Display the report.
rptview(rpt);