Main Content

mlreportgen.dom.TemplateDocumentPart class

Package: mlreportgen.dom

Create template for document part

Since R2023b

Description

This class defines a document part template object that you can add to the TemplateDocumentParts property of an object of the mlreportgen.dom.Template class. When you close the Template object, Report Generator writes these document part templates to the output template package (HTML, PDF, DOCX) or template document (HTML-FILE) as document parts. You can then create DocumentPart objects based on the document part templates in the generated template.

The mlreportgen.dom.TemplateDocumentPart class is a handle class.

Class Attributes

HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

tdpObject = mlreportgen.dom.TemplateDocumentPart() creates a TemplateDocumentPart object and sets the Name property to ''.

example

tdpObject = mlreportgen.dom.TemplateDocumentPart(Name) creates a template object and sets the Name property to Name.

Input Arguments

expand all

Name of the document template part, specified as a character vector or a string scalar. Use the name to identify and access the document part in the generated template.

Properties

expand all

Children of the container, specified as a cell array of mlreportgen.dom.Element objects.

Attributes:

SetAccess
private

ID for this document element, specified as a character vector or string scalar. The DOM generates a session-unique ID when it creates the document element. You can specify your own ID.

Attributes:

NonCopyable
true

Data Types: char | string

HTML tag name of container, specified as a character vector. The name must be an HTML element, such as 'div', 'section', or 'article'.

Note

Microsoft® Word output ignores the HTML tag name.

Data Types: char

Name of the document part, specified as a character vector or string scalar. Use the name to identify and access the document part in the generated template.

Data Types: char | string

Parent of this document element, specified as a DOM object.

Attributes:

SetAccess
private
NonCopyable
true

Format specification, specified as an array of format objects. The formats specified by this property override corresponding formats specified by the StyleName property of this element. Formats that do not apply to this element are ignored.

Style name, specified as a character vector. The style name is the name of a style specified in the style sheet of the document or document part to which this element is appended. The specified style defines the appearance of this element in the output document unless overridden by the formats specified by the Style property of this element.

Note

Microsoft Word output ignores the style name.

Data Types: char

Tag for this document element, specified as a character vector or string scalar.

The DOM generates a session-unique tag as part of the creation of this object. The generated tag has the form CLASS:ID, where CLASS is the object class and ID is the value of the Id property of the object. Specifying your own tag value can help you to identify where an issue occurred during document generation.

Attributes:

NonCopyable
true

Data Types: char | string

Methods

expand all

Examples

collapse all

Import the mlreportgen.dom package so that you do not have to include the package name when you call the object constructors and methods.

import mlreportgen.dom.*

Create a DOCX template.

t = Template("bookReportTemplate","docx");
open(t);

Create a document part template.

dpt = TemplateDocumentPart("bookRatingPart");

Create a hole for a book title.

title = Heading1();
append(title,TemplateHole("Title","Title of the book"));
append(dpt,title);

Create a hole for a book author.

author = Heading2();
append(author,TemplateHole("Author","Author of the book"));
append(dpt,author);

Create a hole for a book rating.

rating = Paragraph("I rate this book: ");
rating.WhiteSpace = "preserve";
append(rating,TemplateHole("Rating", "Rating of the book"));
append(rating," out of 5 stars.");
append(dpt,rating);

Add the document part to the template.

t.TemplateDocumentParts(end+1) = dpt;
close(t);

Open bookReportTemplate.dotx by using one of these methods:

  • In MATLAB®, in the Current Folder pane, right-click the template file and click Open Outside MATLAB.

  • Outside of MATLAB, right-click the template file and click Open.

Template snippet showing book rating document part

Version History

Introduced in R2023b