Main Content

mlreportgen.report.TextFile Class

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

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

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,...).

example

Properties

expand all

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

Example: tf.FileName = "Name of File"

Attributes:

GetAccess
public
SetAccess
public

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"

Attributes:

GetAccess
public
SetAccess
public

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)"

Attributes:

GetAccess
public
SetAccess
public

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"

Attributes:

GetAccess
public
SetAccess
public

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"

Attributes:

GetAccess
public
SetAccess
public

Source of the template for this reporter, specified in one of these ways:

  • Character vector or string scalar that specifies the path of the file that contains the template for this reporter

  • Reporter or report whose template this reporter uses or whose template library contains the template for this reporter

  • Document Object Model (DOM) document or document part whose template this reporter uses or whose template library contains the template for this reporter

The specified template must be the same type as the report to which you append this reporter. For example, for a Microsoft® Word report, TemplateSrc must be a Word reporter template. If the TemplateSrc property is empty, this reporter uses the default reporter template for the output type of the report.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Name of the template for this reporter, specified as a character vector or string scalar. The template for this reporter must be in the template library of the template specified by the TemplateSrc property of this reporter.

Attributes:

GetAccess
public
SetAccess
public

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.

Attributes:

GetAccess
public
SetAccess
public

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