Main Content

add

Class: mlreportgen.report.Report
Namespace: mlreportgen.report

(Not recommended) Add content to report

Syntax

add(report,content)

Description

Note

add is not recommended. Use append instead. See Compatibility Considerations.

add(report,content) adds the specified content to the specified report. If the report is not already open, the add method opens it.

Note

You can add a reporter to a report multiple times, but you cannot add the reporter to different reports. For example, if you add an mlreportgen.report.TitlePage reporter to one report, you cannot add it to another report.

Input Arguments

expand all

Report, specified as an mlreportgen.report.Report object.

Content to add to report, specified as a Report API reporter, DOM object, or built-in MATLAB® object. The content can be a Report API reporter or any object that you can append to a DOM document. Content that you can append to a DOM document includes DOM objects and many built-in MATLAB objects, such as strings, character vectors, and cell arrays.

Examples

expand all

Add content to a paragraph and add the paragraph to a report. To add the content to the paragraph, you must use append because a paragraph is a DOM API object. To add the paragraph to the report, which is a Report API object, this example uses add. Starting in R2020b, you can use append instead of add. See Compatibility Considerations.

import mlreportgen.dom.*
import mlreportgen.report.*

rpt = Report("My Report");
p = Paragraph("My paragraph content ");

append(p,"and some more content.");
add(rpt,p);

close(rpt);
rptview(rpt);

Version History

Introduced in R2017b

collapse all

R2020b: add method is not recommended

Starting in R2020b, use the append method instead of the add method to add content to objects of these Report API classes:

  • mlreportgen.report.Report

  • mlreportgen.report.Chapter

  • mlreportgen.report.Section

To add content to a DOM API object, such as an mlreportgen.dom.Paragraph object, continue to use the append method of the DOM object. The advantage of using append to add content to Report API objects is that you use the same method name as you use to add content to DOM API objects.

There are no plans to remove the add methods of the Report, Chapter, or Section classes. Report API programs that use the add methods will continue to run.

To update existing code, replace the method name add with append as shown by the examples in the table.

Not RecommendedRecommended
import mlreportgen.report.*
import mlreportgen.dom.*

rpt = Report("My Report","pdf");
ch = Chapter("My Chapter");
sect = Section("My Section");
para = Paragraph("My Content ");
append(para,"more Content");
add(sect,para);
add(ch,sect);
add(rpt,ch);

close(rpt);
rptview(rpt);
import mlreportgen.report.*
import mlreportgen.dom.*

rpt = Report("My Report","pdf");
ch = Chapter("My Chapter");
sect = Section("My Section");
para = Paragraph("My Content ");
append(para,"more Content");
append(sect,para);
append(ch,sect);
append(rpt,ch);

close(rpt);
rptview(rpt);