Main Content

mlreportgen.report.RptFile Class

Namespace: mlreportgen.report
Superclasses: mlreportgen.report.Reporter

Create Report Explorer-based reporter

Description

Use the RptFile reporter to include the content generated by a Report Explorer setup (.rpt) file in a Report API report. When added to a report, the RptFile reporter:

  1. Executes the specified Report Explorer setup file to generate a DocBook XML rendition of the Report Explorer report

  2. Uses a modified version of the Report Explorer Docbook-to-DOM conversion template to convert the XML to a set of DOM objects (see Manage Report Conversion Templates)

  3. Adds the DOM content to the Report API report.

The mlreportgen.report.RptFile class is a handle class.

Creation

Description

reporter = RptFile creates an empty Report Explorer-based RptFile reporter. Before adding the reporter to a report, your report program must set the reporter's SetupFile property to the path of a Report Explorer setup (.rpt) file. Otherwise, an error occurs.

By default the RptFile reporter uses a conversion template that is a slightly modified version of the Report Explorer's default conversion template for the report output type. For example, if the report output type is PDF, the reporter uses a slightly modified version of the default template for the Report Explorer's PDF (from template) output type.

You can use a custom conversion template to customize the reporter output. Use the reporter's createTemplate method to create a copy of one of the reporter's default output-type-specific conversion templates for customization. To use the customized template, set the RptFile reporter's TemplateSrc property to the path of the customized template.

example

reporter = RptFile(SetupFile) creates a RptFile reporter based on the specified Report Explorer setup file (.rpt file). See the SetupFile property.

example

reporter = RptFile(Name=Value) sets properties using name-value pairs. You can specify multiple name-value pair arguments in any order.

Properties

expand all

Report Explorer setup file path, specified as a character vector or string. Do not use form-based reports for setup files that you use with the RptFile reporter.

Attributes:

GetAccess
public
SetAccess
public

Data Types: char | string

Source of conversion template to be used by this reporter to convert the setup file's XML output to DOM objects. An empty value specifies use of the default template for the output type of the report to be generated. A character vector or string scalar value specifies the path of a customized version of the default template for the output type to be generated.

Data Types: char | string

Name of template for this reporter, specified as a character vector or string. By default this property specifies RptFile, the name of the reporter's default template. This default template resides in the template library of its default conversion template along with other templates used to convert Report Explorer XML components to DOM objects. The default reporter template contains a single hole named Content to be filled with the DOM content converted from the XML content generated by the setup. If you change the name of this template, you must set this property to the new name. You can modify the template itself, but the modified template must contain a hole named Content.

Data Types: char | string

Hyperlink target for this reporter, specified as a character vector or string scalar that specifies the link target ID, or an mlreportgen.dom.LinkTarget object. A character vector or string scalar value converts to a LinkTarget object. The link target immediately precedes the content of this reporter in the output report.

Methods

expand all

Examples

Create a RptFile Reporter

Create an RptFile reporter without specifying a setup file. Then, use the SetupFile property to specify the Report Explorer setup file.

reporter = mlreportgen.report.RptFile();
reporter.SetupFile = "my_setup_file.rpt" 
 

Add Syntax-Highlighted Code to a Report

Use the RptFile reporter to add syntax-highlighting to code in a Report API Report.

Note

Before you run this example, use the Report Explorer to create a setup file named highlight_syntax.rpt. The setup file for this example contains a Preformatted component with this text in its edit box:

% To import the Report API namespace, use this command:
%<code_var>
Enable Show text as syntax-highlighted MATLAB code, which is below the Preformatted text box. See Create a Report Setup File.

Report Explorer showing the box Show text as syntax-highlighted MATLAB code selected in the Properties pane

This code creates a Report API report that includes the highlight_syntax.rpt setup file.

rpt = mlreportgen.report.Report("My Report","pdf");

chap = mlreportgen.report.Chapter...
  ("Include Report Explorer Report Using the RptFile Reporter");
sect1 = mlreportgen.report.Section...
  ("Highlighted Syntax Example");

% Evaluate the expression and assign it to the code variable
evalin('base','code_var = "import mlreportgen.report.*"');

rptfile = mlreportgen.report.RptFile("highlight_syntax.rpt");

add(sect1,rptfile)
add(chap,sect1)
add(rpt,chap)

close(rpt)
rptview(rpt)

Report sample showing Chapter 1. Include Report Explorer Report Using the RptFile Reporter, section 1.1 Highlighted Syntax Example, and a code sample that shows "% To import the Report API Package, use this command:" in green, "import" in black and "mlreportgen.report.*" in red

Version History

Introduced in R2019a