Main Content

append

Class: mlreportgen.dom.Document
Namespace: mlreportgen.dom

Append DOM or MATLAB object to document

Description

domObjOut = append(docObj,textContent) appends text or numbers to a document and returns a text object. In Microsoft® Word and PDF output, the text is wrapped in a paragraph because Word and PDF do not permit unwrapped text to be added to the body of a document. In HTML output, the text is not wrapped in a paragraph.

domObjOut = append(docObj,listContent) appends an unordered list and returns an unordered list object.

domObjOut = append(docObj,tableContent) appends a table and returns a table object.

example

domObjOut = append(docObj,paraObj,pageLayoutObj) appends a paragraph, starts a new page layout section whose properties are specified by the pageLayoutObject, and returns a paragraph object.

domObjOut = append(___,styleName) appends the specified content, using the specified style.

example

domObjOut = append(docObj,domObj) appends a DOM object to the document and returns that object.

example

Input Arguments

expand all

Document to which to append content, specified as an mlreportgen.dom.Document object.

Text to append to document, specified as a character vector or string scalar. The text object is wrapped in a paragraph object and the paragraph is appended to the document. The text is wrapped in a paragraph to be consistent with Microsoft Word, which does not allow text to be added to the body of a document. For HTML, text wrapping can cause unexpected behavior.

List object to append to document, specified as an ordered list, unordered list, or an array. If the input is a 1D horizontal array of double values or strings, or a 1D categorical array, an unordered list object is created and that list object is appended it to the document.

Table object to append to document, specified as one of:

  • 2D array of double values — Appends and returns a Table object

  • 2D array of strings — Appends and returns a Table object

  • 2D categorical array — Appends and returns a Table object

  • Cell array of strings for the table header and a numeric, cell, or categorical array for the table body — Appends and returns a FormalTable object

  • MATLAB table — Appends and returns a MATLABTable object

Paragraph to append to document, specified as a paragraph object. It also starts a new page layout section with properties specified by the pageLayoutObj input.

Page layout to apply to the appended page layout section, specified as a PageLayout object.

Style to apply to text, table or list input.

DOM object to append to document, specified as any of these mlreportgen.dom objects:

  • Container

  • CustomElement

  • DOCXPageLayout

  • ExternalLInk

  • FormalTable

  • Group

  • HorizontalRule

  • HTML

  • HTMLFile

  • HTMLPage

  • Image

  • InternalLInk

  • LineBreak

  • LinkTarget

  • MATLABTable

  • NumPages

  • OrderedList

  • Page

  • PageBreak

  • PageRef

  • Paragraph

  • PDFPageLayout

  • RawText

  • StyleRef

  • Table

  • Text

  • UnorderedList

Output Arguments

expand all

Appended object returned. The type of object depends on the second input type.

Examples

Append an Ordered List Object

Create an OrderedList object and append it to a report.

import mlreportgen.dom.*;
d = Document('mydoc','html');

ol = OrderedList({'first step' 'second step' 'last step'});
append(d,ol);

close(d);
rptview('mydoc','html');

Specify a Style for Appended Text

Use the Word Title style for the text.

import mlreportgen.dom.*;
d = Document('mydoc','docx');
append(d,'This Is a Title','Title');
close(d);
rptview('mydoc','docx');

Append a MATLAB Table

% Create a MATLAB table named patients from workspace variables. 
load patients;
BloodPreasure = [Systolic Diastolic];
patients = table(Gender,Age,Smoker,BloodPreasure);
patients.Properties.RowNames = LastName;

% Sort the table based on the Age variable. 
sorted = sortrows(patients,'Age');

% Create a report with the sorted patients table 
rpt = mlreportgen.dom.Document('MyFileName','pdf');
append(rpt,sorted);
close(rpt);

% Show the PDF report in the viewer
rptview(rpt.OutputPath);

Append a Cell Array as a Table

import mlreportgen.dom.*;
d = Document('mydoc');
table = append(d,{'row 1 - col 1' 'row 1 - col 2';...
    'row 2 - col 1' 'row 2 - col 2'});
table.Style = {Border('double'),ColSep('solid'),RowSep('solid')};
close(d);
rptview('mydoc','html');

Version History

Introduced in R2014b