mlreportgen.report.TableOfContents class
Package: mlreportgen.report
Superclasses: mlreportgen.report.Reporter
Table of contents reporter
Description
Create a table of contents (TOC) reporter that adds a table of contents to the report.
This class inherits from mlreportgen.report.Reporter
.
Construction
returns a reporter
that generates a table of contents (TOC) section for the report. The default template
for the TOC section defines the appearance and page layout of the TOC. The TOC section
contains a default title and a TOC element that specifies the location of a TOC to be
generated, depending on the report output type. The way in which the TOC is generated
differs for each report type. toc
= TableOfContents()
HTML — JavaScript copied from the report template to the report generates the TOC when the report is opened in a browser. The script generates the TOC as a collapsible tree. The tree entries are the hyperlinked contents of the HTML heading elements (h1-h6) of the report. The level of an entry in the TOC tree corresponds to the level of the heading element. Chapter and section reporters generate chapter and section titles as heading elements of the appropriate level, so chapter and section titles appear automatically in the TOC. You can also use DOM Heading elements in a report to generate TOC entries.
DOCX — The Report Generator
rptview
function instructs Word to generate the TOC after it opens the report in Word. If you open a report in Word directly, without usingrptview
, you must update the report document yourself to generate the TOC. See Update a Table of Contents or Generated List in a Word Document.The TOC is a two-column table. The first column contains the hyperlinked contents of report paragraphs whose outline levels have been set. The outline level determines the formatting of a TOC entry. The second column contains the number of the page on which the corresponding paragraph occurs. Chapter and section reporters generate chapter and section titles as paragraphs with the appropriate level set, so chapter and section titles appear automatically in the TOC. You can also use DOM Heading elements in a report to generate TOC entries.
PDF — The table of contents is generated during PDF document generation.
creates a TOC that uses the specified toc
= TableOfContents(title
)title
.
sets properties using name-value pairs. You can specify multiple name-value pair
arguments in any order.toc
= TableOfContents(Name=Value
)
Properties
Methods
createTemplate | Create table of contents section template |
customizeReporter | Create custom table of contents reporter class |
getClassFolder | Table of contents class definition file location |
getTitleReporter | Get table of contents title reporter |
Examples
Default Table of Contents
Create a table of contents that uses the default formatting.
import mlreportgen.report.* rpt = Report('output','pdf'); toc = TableOfContents(); add(rpt,toc);
Customized Table of Contents
Create a report that includes a table of contents with a title in green. This report also includes chapters, sections, and an appendix section.
import mlreportgen.report.* import mlreportgen.dom.* rpt = Report('Report with TOC'); add(rpt, TitlePage(Title='Report',Subtitle='with TOC')); toc = TableOfContents; toc.Title = Text('Table of Contents'); toc.Title.Color = 'green'; toc.NumberOfLevels = 2; add(rpt,toc); ch = Chapter('First Chapter'); add(ch,Section('First Subsection')); add(ch,Section('Second Subsection')); add(rpt,ch); add(rpt,Chapter('Second Chapter')); add(rpt,PDFPageLayout); p = Paragraph('Appendix'); p.Style = {OutlineLevel(1), Bold, FontSize('18pt')}; add(rpt,p); close(rpt); rptview(rpt);