User`s guide
Add Content to a Report
13-11
Add Content to a Report
The DOM append function allows you to add content to documents, paragraphs, tables,
and other DOM objects that serve as containers for report content. The append function
takes two arguments. The first argument is the object to which the content is to be
appended. The second is the content to be appended. In this example, the text Hello
World is appended to the document.
d = Document('MyReport');
append(d,'Hello World');
The append function throws an error if the second argument (the content to be
appended), is incompatible with the first argument (the object to which the content is to
be appended). For example, the append method in the following script throws an error.
% This code throws an error
image = Image('membrane.png');
append(image,Paragraph('Hello World'));
This is because you cannot add a paragraph to an image. The reference documentation
for classes lists the types of objects that you can append to instances of the classes. To
get a complete list of DOM API classes and functions in the MATLAB Report Generator
documentation, open the Functions pane. To see the documentation reference page for
an object, search in documentation or in MATLAB use a doc command such as this.
doc mlreportgen.dom.Paragraph
As shown in the preceding examples, the append method, depending on the target object
type, allows you to append strings, doubles, arrays, and other basic MATLAB data types,
without first converting the data to DOM objects. The function converts the appended
data to a DOM object before appending it to the target object. For example, the following
script appends a two-dimensional array of strings to a document as a table.
d = Document('MyDoc');
tableArray = {'a','b';'c','d'};
append(d,tableArray);
Many constructors also allow you to specify basic MATLAB data types as the initial
content of the object when you construct the object. This example is equivalent to the
preceding example.
d = Document('MyDoc');
tableArray = {'a','b';'c','d'};