Main Content

mlreportgen.dom.Container Class

Namespace: mlreportgen.dom

Container of document objects

Description

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 Document Object Model (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.

Tip

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.

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

Class Attributes

HandleCompatible
true
ConstructOnLoad
true

For information on class attributes, see Class Attributes.

Creation

Description

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

example

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'.

Note

Word output ignores the HTML container tag.

Output Arguments

expand all

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

Properties

expand all

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 | string

Style name, specified as a character vector or a string scalar. 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. To learn more about using style sheets, see Use Style Sheet Styles.

Note

Microsoft Word output ignores the style name.

Attributes:

NonCopyable
true

Data Types: char | string

Format specification for this document element object, 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.

Attributes:

NonCopyable
true

Data Types: cell

Parent of mlreportgen.dom.Container object, specified as a document element object. A document element must have only one parent.

Attributes:

SetAccess
private
NonCopyable
true

Children of mlreportgen.dom.Container object, specified as an array of document element objects. This property contains the document element objects appended using the append method.

Attributes:

SetAccess
private
NonCopyable
true

Tag for mlreportgen.dom.Container object, specified as a character vector or string scalar. The DOM API 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. Specify your own tag value to help you identify where to look when an issue occurs during document generation.

Attributes:

NonCopyable
true

Data Types: char | string

Object identifier for mlreportgen.dom.Container object, specified as a character vector or string scalar. The DOM API generates a session-unique identifier when it creates the document element object. You can specify your own value for Id.

Attributes:

NonCopyable
true

Data Types: char | string

Methods

expand all

Examples

collapse 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.

append(c,Paragraph('Hello'));
append(c,Table(magic(5)));
append(rpt,c);

Close and generate the report.

close(rpt);
rptview(rpt.OutputPath);

Version History

Introduced in R2015a