User`s guide
13 Create a Report Program
13-82
toc = CustomElement('div');
toc.CustomAttributes = {CustomAttribute('id', 'toc')};
append(toc, CustomText()); % Workaround for browser bug
append(d, toc);
append(d, Heading(1, 'Chapter 1'));
append(d, Heading(2, 'Section 1'));
close(d);
rptview(d.OutputPath);
Insert a Placeholder Programmatically Using a Document Part
The document part template library of the DOM default template contains a document
part for creating a TOC placeholder. If you use this template or a template based on it,
you can use the document part to insert a TOC placeholder in your report. For example:
import mlreportgen.dom.*;
d = Document('MyReport','html');
append(d,'My Report');
append(d, DocumentPart(d,'ReportTOC'));
append(d, Heading(1,'Chapter 1'));
append(d, Heading(2,'Section 1'));
close(d);
rptview(d.OutputPath);
Set Outline Levels of Section Heads
To generate a table of contents in a Word or HTML report, your program must set the
outline levels of the section heads that you want to appear in the table. An outline level
is a paragraph format property that specifies whether and at what level a paragraph’s
contents appear in a table of contents. For example, if a paragraph has an outline level of
1, its content appears at the top level of the generated table of contents. You can use up
to nine distinct outline levels.
To set the outline level of paragraphs, use one of these approaches.
• “Use Template-Defined Styles to Set Outline Levels” on page 13-83
• “Use Format Objects to Set Outline Levels” on page 13-83
• “Use Heading Objects to Set Outline Levels” on page 13-83