Main Content

add

Class: mlreportgen.report.Section
Namespace: mlreportgen.report

(Not recommended) Add content to section

Syntax

add(section,content)

Description

Note

add is not recommended. Use append instead. See Version History.

add(section,content) adds the specified content to the specified section.

Input Arguments

expand all

Section of the report, specified as an mlreportgen.report.Section object.

Content to add to the section, specified as one of these values:

  • Report API reporter

  • DOM object

  • Built-in MATLAB® object (most built-in MATLAB objects can be added to a Section reporter)

  • Cell array of objects that can be added individually to a section

Examples

expand all

Add content to a paragraph and add the paragraph to a section of a chapter. 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 section, the section to the chapter, and the chapter to the report, this example uses add. Starting in R2020b, you can use append instead of add. See Version History.

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

rpt = Report("My Report");
ch = Chapter("My Chapter");
s = Section("My Section");
p = Paragraph("My paragraph content ");
append(p,"and some more content.");
add(s,p);
add(ch,s);
add(rpt,ch);

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