Contenuto principale

append

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

Append DOM or MATLAB object to document

Description

domObjOut = append(docObj,textContent) appends text or numbers, textContent, to a document, docObj, 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,listContent, and returns an unordered list object.

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

example

domObjOut = append(docObj,paraObj,pageLayoutObj) appends a paragraph,paraObj, 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 style, styleName.

example

domObjOut = append(docObj,domObj) appends a DOM object, domObj, 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 one of these:

  • mlreportgen.dom.OrderedList object

  • mlreportgen.dom.UnorderedList object

  • 1D horizontal array of double values or strings — Appends and returns a mlreportgen.dom.UnorderedList object

  • 1D categorical array — Appends and returns a mlreportgen.dom.UnorderedList object

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

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 mlreportgen.dom.DOCXPageLayout or mlreportgen.dom.PDFPageLayout object.

Style to apply to text, table or list input, specified as a character vector or a string scalar.

Output Arguments

expand all

Appended document element, returned as the same DOM object type as the input object.

Examples

expand all

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

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

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.

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

Tips

Version History

Introduced in R2014b