This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materials including this page, select Japan from the country navigator on the bottom of this page.

mlreportgen.dom.Container class

Package: mlreportgen.dom

Container of document objects


Creates a container element. Use the mlreportgen.dom.Container.append method to append document elements to the container. Use an mlreportgen.dom.Container object in a report to apply formats to all of the children of the container.

In HTML output, a Container object generates an HTML element of the type specified by its HTMLTag property and containing HTML elements corresponding to its DOM contents. For example, a Container object with the HTMLTag property div and that contains the text Hello World generates this markup:

<div><p><span>Hello World</span></p></div>

The generated HTML container element has the class and style properties specified by the Container object StyleName and Style properties, respectively. The rules of HTML CSS format inheritance assure that the generated children of the Container object inherit the formats specified by the Container object Style and StyleName properties. For example, if the Container object specifies red as its text color and none of its text children specify a color, the text children are colored red.

For Microsoft® Word and PDF report output, a Container object simulates container format inheritance, applying the formats specified by the Container object Style attribute to each child, unless overridden by the child, and then appending the child to the output. Word and PDF output ignore the HTMLTag and StyleName properties of the Container object.


You can use mlreportgen.dom.Container or mlreportgen.dom.Group objects to produce collections of document elements.

  • Use a container object to apply format inheritance to a set of objects and to create HTML container elements not otherwise supported by the DOM, such as div, section, and article.

  • Use a group object to append the same content in multiple places in a document without cloning the group.


containerObj = Container() creates a container with an HTML tag name div.


containerObj = Container(HTMLtag) creates a container with the specified HTML tag name (for example, div, section, or article).

Input Arguments

expand all

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


Word output ignores the HTML container tag.

Output Arguments

expand all

Container of document objects, returned as an mlreportgen.dom.Container object.


expand all

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

This read-only property lists child elements that the container contains.

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


Word output ignores the HTML container tag.

This read-only property lists the parent of this document element.

Format specification, specified as an array of format objects. The formats specified by this property override corresponding formats defined by the style sheet style 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 where not overridden by the formats specified by the Style property of this element.


Word output ignores the style name.

Tag for document element, specified as a character vector.

A session-unique ID is generated as part of document element creation. The generated tag has the form CLASS:ID, where CLASS is the class of the element and ID is the value of the Id property of the object. You can specify a tag to replace the generated tag.

For example, to make it easier to identify where an issue occurred during document generation, you can specify your own tag value.


appendAppend DOM object to container
cloneCopy container object


expand all

Create a container object. Word output ignores the HTML container element tag (in this example, the div tag).

import mlreportgen.dom.*;
rpt = Document('MyReport','docx');

c = Container();

Color all of the container text red.

c.Style = {Color('red')};

Append content to the container and append the container to the report.


Close and generate the report.


Introduced in R2015a

Was this topic helpful?