append

Class: mlreportgen.dom.Document
Package: 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 element object.

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

example

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

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

example

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.

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 string or character vector. 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, unorderedlist, or an array. If the input is a 1D horizontal array of double values or strings, or a 1D categorical array, an unorderedlist 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

  • Image

  • InternalLInk

  • LineBreak

  • LinkTarget

  • MATLABTable

  • NumPages

  • OrderedList

  • Page

  • PageBreak

  • PageRef

  • Paragraph

  • PDFPageLayout

  • RawText

  • StyleRef

  • Table

  • Text

  • UnorderedList

Output Arguments

expand all

Appended object returned. They 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');

Introduced in R2014b