Main Content

mlreportgen.report.TextFile Class

Namespace: 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

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

Example: tf.FileName = "Name of File"

Data Types: char | string

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'

Data Types: logical

Paragraph separator, specified as a character vector or string scalar. 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)'

Data Types: char | string

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'

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 namespaces 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