Main Content

Add Content to Reports

Report API and DOM API objects that serve as containers for report content have an append method that you use to add content to the objects. For example, objects of these classes have an append method:

The append methods take two arguments. The first argument is the object to append the content to and the second argument is the content to append to the object.

Here is an example that adds a paragraph to a chapter and a chapter to a report:

import mlreportgen.report.* 
import mlreportgen.dom.*
rpt = Report("My Report");
ch = Chapter("My Chapter");
p = Paragraph("Hello World");
append(ch,p);
append(rpt,ch);
close(rpt);
rptview(rpt);

For some DOM API objects, such as paragraphs, you can specify the content when you create the object. Then, you can append more content to the object. For example, this code specifies the initial content for a paragraph, appends more content to the paragraph, and appends the paragraph to the document:

import mlreportgen.dom.*
d = Document("My Document");
p = Paragraph("Hello World.");
append(p," It's me");
append(d,p);
close(d);
rptview(d);

You can append DOM API objects and many built-in MATLAB® objects, such as strings, character vectors, and cell arrays, to DOM API and Report API container objects. You can also append other Report API objects to Report API container objects. If the content that you try to append to an object is not supported for the object, the append method returns an error. For information about the content that you can append to a particular Report API or DOM API object, see the reference pages for the object and the append method of the object. For information about creating content, see Content Generation.

See Also

Functions

Related Topics