Main Content

mlreportgen.report.TextFile class

Package: mlreportgen.report

Text file reporter

Since R2023a

Description

Create a reporter to report on text files.

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

Class Attributes

HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

example

reporter = TextFile() creates an empty TextFile reporter object based on a default template. Use its properties to specify a text file on which to report and to specify report options. You must specify a text file name to be reported. Adding an empty TextFile reporter object, that is, one that does not specify a file name, to a report, produces an error.

reporter = TextFile(filename) creates a TextFile reporter object with the FileName property set to filename. Adding this reporter to a report, without any further modification, adds the text file content to the generated report. Use the reporter's properties to customize the report options.

reporter = TextFile(p1,v1,p2,v2,...) creates a TextFile reporter and initializes properties (p1,p2,...) to the specified values (v1,v2,...).

Properties

expand all

Public Properties

Path or name of the text file, specified as a character array.

Example: tf.FileName = "Name of File"

Specifies whether to import the file as a DOM Paragraph or DOM Text object. When set to true, MATLAB® imports the file as a DOM Paragraph object. The input is broken into paragraphs at values set by the ParaSep property. Use ParagraphFormatter property whose value is a DOM Paragraph object to format the DOM Paragraph objects. If the property is set to false, MATLAB imports the text file a DOM Text object. Use TextFormatter property whose value is a DOM Text object to format the DOM Text object.

Example: 'ImportFileAsParagraph','false'

Paragraph separator, specified as a string scalar or character vector. Use this property to specify the separator used to break the input into paragraphs. You can use any separator. For example, newline separates the input text at a line break and wraps the text into paragraphs.

Example: 'ParaSep','char(10)'

If the ImportFileAsParagraph property for the TextFile reporter is true, the reporter appends a plain text paragraph to a copy of this object and appends it to the report. Use mlreportgen.dom.Paragraph object properties to format a plain text paragraph by setting the properties of the default paragraph or by replacing the default paragraph with a custom paragraph. Content that you add to the default or replacement paragraph appears before the content of the generated report.

Example: 'ParagraphFormatter.Color','red'

If the ImportFileAsParagraph property for the TextFile reporter is false, the reporter appends a plain text content to a copy of this object and appends it to the report. Use the mlreportgen.dom.Text object properties to format a plain text content. Content that you add to the default appears before the content of the generated report.

Example: 'TextFormatter.Color','red'

Source of the reporter template, specified as a character vector or string scalar. The value of this property may be a character vector or string scalar that specifies the path of the file that contains the template for this reporter.

The specified template must be of the same type as the report to which this reporter is to be appended. For example, this property must specify a Word reporter template for a Word report. If the property is empty, the report uses the default template. To see the default path, use getDefaultTemplatePath(reporter, report).

Name of template for the reporter, specified as a character vector or string scalar. The template for this reporter must be in the template library of the template source (TemplateSrc) for this reporter. If empty, the template of the reporter is assumed to be the template file specified by the TemplateSrc property.

Hyperlink target for the reporter, specified as a character vector or string scalar that specifies the link target ID or as an mlreportgen.dom.LinkTarget object.

Methods

expand all

Examples

collapse all

Create a report from text file as a paragraph.

First, create a text file and save it as my_script.txt to use with this example. Next, import the report API packages so that you do not have to use long fully qualified class names.

import mlreportgen.report.*

Create a PFD report.

rpt = Report("MyReport","pdf");
open(rpt);

Create an empty chapter.

chap = Chapter("TextFile Reporter");

Create a TextFile reporter. Specify a paragraph separator so the report creates a new paragraph at each newline character.

rptr = TextFile("my_script.txt");
rpt.ParaSep = [newline newline];

Append the reporter to the chapter and append the chapter to the report.

append(chap,rptr);
append(rpt,chap);

Close and view the report.

close(rpt);
rptview(rpt);

Version History

Introduced in R2023a