主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

getTitleReporter

类: mlreportgen.report.Section
命名空间: mlreportgen.report

创建一个节标题报告器

语法

reporter = getTitleReporter(section)

说明

reporter = getTitleReporter(section) 创建 mlreportgen.report.SectionTitle 报告器,其部分配置为:

  • 格式化由 section 指定的 mlreportgen.report.Section 报告器的 Title 属性的值。

  • 用格式化的标题填充 Section 报告器模板中的 Title 空位。

SectionTitle 报告器 getImpl 方法使用 mlreportgen.report.Section.getTitleReporter 方法来格式化内联标题内容。您可以使用 mlreportgen.report.Section.getTitleReporter 方法自定义内联标题格式,如下所示:

  1. 调用 mlreportgen.report.Section.getTitleReporter 方法获取默认的 SectionTitle 报告器。

  2. 自定义 SectionTitle 报告器属性。例如指定包含自定义标题模板的模板源。

  3. Section 报告器的 Title 属性设置为自定义的 SectionTitle 报告器。

您可以通过更改这些 SectionTitle 报告器属性的默认值来自定义标题格式:

  • TemplateSrc

    此属性默认设置为 Section 报告模板。此模板的模板库包含默认的节标题模板,名称如下:

    • SectionTitle1SectionTitle2 等,表示未编号的标题

    • SectionNumberedTitle1SectionNumberedTitle2 等等,用于按层次编号的标题。

    您可以将此属性设置为包含这些模板的自定义定义的模板文件的源。

  • TemplateName

    如果 Section 报告器 "SectionNumberedTitle" 属性为 Numbered(默认值),则此属性默认设置为 true。否则,此属性设置为 "SectionTitle"。如果您的自定义模板库自定义了标准标题模板的定义但没有自定义其名称,则无需更改此设置。例如,如果您的模板库包含一个名为 SectionNumberedTitle1 的模板,并且该模板具有 SectionNumberedTitle1 标准定义的自定义版本,则您不需要更改此属性的值。

  • OutlineLevel

    默认情况下,此属性为空。Section 报告器 getImpl 方法默认调用 getTitleReporter 方法,当 Section 报告器添加到报告中时,将此属性设置为节级别。然后,SectionTitle 报告器将 OutlineLevel 属性的值追加到 TemplateName 属性的值,以创建节级别的 SectionTitle 模板的全名,例如,第二级子节的全名是 SectionNumberedTitle2

  • Content

    此属性默认设置为 Section 报告器 Title 属性的值。

  • NumberPrefix

    此属性默认设置为 []

  • NumberSuffix

    如果 Section ". " 属性为 Numbered(默认值),则此属性设置为 true。否则,此属性设置为 []

  • Translations

    默认情况下未设置此属性。设置此属性可以本地化章节标题编号前缀和后缀标题内容。

输入参数

全部展开

报告的节,指定为 mlreportgen.report.Section 对象。

输出参量

全部展开

章节标题报告器,以 mlreportgen.report.SectionTitle 对象形式返回。

示例

全部展开

以下示例显示如何使用自定义模板生成报告中一级节的标题。

假设 MyCustomTemplate.pdftx 包含标准模板 SectionNumberedTitle1 的自定义版本。

要使用自定义模板:

  1. 获取该节的 SectionTitle 报告器。

  2. 将报告器的 TemplateSrc 属性设置为 MyCustomTemplate.pdftx,并将 OutlineLevel 属性设置为该节的级别。

  3. Section 报告器的 Title 属性设置为 SectionTitle 报告器。

例如:

import mlreportgen.report.*

rpt = Report("myrpt","pdf");

sec = Section("Title","Introduction");
titleRptr = getTitleReporter(sec);
titleRptr.TemplateSrc = "MyCustomTemplate.pdftx";
titleRptr.OutlineLevel = 1;
sec.Title = titleRptr;
add(rpt,sec);
close(rpt);

版本历史记录

在 R2017b 中推出