Main Content

Create a Report Program

TheMATLAB®Report Generator™包括g类允许您创建报告enerator programs. These programs can generate 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), seeWhat Is a Reporter?.

Required Report Program Tasks and Elements

All report generator programs must:

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. SeeImport the API Packages.

  • 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. SeeContent Generation.

  • Add content to reporters by using theaddmethod.

    Note

    The only reporters you can both configure and add content to are theSectionandChapterreporters. TheChapterreporter is a subclass of theSectionreporter.

  • Display the report to see the generated report output. SeeDisplay Report.

  • Display report progress messages to monitor report progress. SeeDisplay Progress and Debugger Messages.

Report Generator Program Example

For example, this MATLAB code generates and displays a PDF report. It includes both required and optional items:

% Import report API classes (optional)importmlreportgen.report.*% Add report container (required)rpt = Report('output','pdf');% Add content to container (required)% Types of content added here: title% page and table of contents reporterstitlepg = TitlePage; titlepg.Title ='My Airplane'; titlepg.Author ='Pilot A'; add(rpt,titlepg); add(rpt,TableOfContents);% Add content to report sections (optional)% Text and formal image added to chapterchap = Chapter('Plane Image'); add(chap,'Here is the plane:'); add(chap,FormalImage('Image',...which('b747.jpg'),'Height','5in',...'Width','5in','Caption','Boeing 747')); add(rpt,chap);% Close the report (required)close(rpt);% Display the report (optional)rptview(rpt);

Report title page with the title

Table of contents listing one image

A Boeing 747

Related Topics