Main Content

mlreportgen.dom.TOC Class

Namespace: mlreportgen.dom

Create placeholder for generating table of contents

Description

Create a placeholder for a document table of contents. When a generated Word document opens, Word replaces the placeholder with a TOC that it generates. Similarly, when a generated HTML document opens in an HTML browser, the browser replaces the placeholder with a TOC that it generates. For PDF, the DOM API replaces the placeholder with a TOC that it generates when outputting the document.

In all cases, the TOC entries consist of the content of paragraphs using the number of heading levels that you specify. For PDF and Word, the TOC placeholder also specifies a leader that fills the space between the content and the page number in the TOC entry.

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

Creation

Description

toc = TOC generates a three-level TOC that uses a dot leader.

toc = TOC(levels) uses the specified number of heading levels.

toc = TOC(levels,leader) uses the specified leader.

example

Input Arguments

expand all

Number of heading levels to use in TOC, specified as a positive integer.

Type of leader to use between title and page number, specified as "." (i.e., period or dot) or " " (a space).

Properties

expand all

Type of leader to use between title and page number, specified as "." (i.e., period or dot) or " " (a space).

Number of heading levels to use in the TOC, specified as a positive integer.

Format specification for this document element object, specified as an array of DOM 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 document element object are ignored.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Name of stylesheet-defined style, specified as a character vector or 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 the formats specified by the Style property of this element override it. To learn more about using style sheets, see Use Style Sheet Styles.

Note

Microsoft® Word reports ignore style names that are not defined in the document template. For more information on Microsoft Word templates, seeTemplates for DOM API Report Programs.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Data Types: char | string

Custom attributes of the document element, specified as an array of mlreportgen.dom.CustomAttribute objects. The custom attributes must be supported by the output format of the document element to which this object is appended.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

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

Attributes:

GetAccess
public
SetAccess
private
NonCopyable
true

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

Attributes:

GetAccess
public
SetAccess
private
NonCopyable
true

Tag, 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. Use this value to help identify where an issue occurs during document generation.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Data Types: char | string

Object identifier, specified as a character vector or string scalar. The DOM API generates a session-unique identifier when it creates the document element object.

Attributes:

GetAccess
public
SetAccess
public
NonCopyable
true

Data Types: char | string

Examples

collapse all

This example adds a table of contents to a document using a TOC object. This document contains three levels of heads—|Heading1|, Heading2, and Heading3. Because the TOC object specifies only two heading levels, Heading3 is not included in the TOC. The leader is a space.

import mlreportgen.dom.*;
d = Document('mydoc','pdf');
open(d);

title = append(d, Paragraph('My TOC Document'));
title.Bold = true;
title.FontSize = '28pt';

toc = append(d,TOC(2,' '));
toc.Style = {PageBreakBefore(true)};

h1 = append(d,Heading1('Chapter 1'));
h1.Style = {PageBreakBefore(true)};
p1 = append(d,Paragraph('Hello World'));

h2 = append(d,Heading2('Section 1.1'));
h2.Style = {PageBreakBefore(true)};
p2 = append(d,Paragraph('Another page'));

h3 = append(d,Heading3('My Subsection 1.1.a'));
p3 = append(d, Paragraph('My Level 3 Heading Text'));

close(d);
rptview(d.OutputPath);

Tips

The document template style determines the size, spacing, color, and other format properties of the TOC generated by this object. Consequentially, you must redefine the styles in the document template, not in the template used by a document part that contains this object. To change the format of the entries in your TOC, create a custom document template that redefines these styles and use the template when you generate your document. The default Microsoft Word and PDF templates of your mlreportgen.dom.Document object contain default styles for each entry in the TOC. The styles are named TOC1, TOC2, …, TOC6, where style TOC1 defines the format of level 1 entries, style TOC2 defines the format of level 2 entries, etc.

Version History

Introduced in R2016a