mlreportgen.report.Chapter 类
命名空间: mlreportgen.report
超类: mlreportgen.report.Section
章报告器
描述
使用 mlreportgen.report.Chapter 类的对象向报告添加章节。
mlreportgen.report.Chapter 类是一个 handle 类。
创建对象
描述
创建了一个生成章节的报告器。本章节具有由报告器的默认模板定义的新页面布局。 ch = mlreportgen.report.Chapter
默认模板是带有页眉和页脚的纵向页面。标头为空。如果某一章是报告的第一章,则页脚包含自动生成的以 1 开头的页码。如果该章节不是第一章,则页码从上一章的最后一页继续。使用 Layout 属性来覆盖章节的某些页面布局功能,例如方向。
使用 Title 属性指定标题。
要向章节添加内容,请使用 append 对象的 mlreportgen.report.Chapter 方法。
注意
在向报告添加章节之前,请先将所有内容添加到该章节中。一旦将章节添加到报告中,就无法向该章节添加更多内容。
使用名称-值参量设置属性。您可以按任意顺序指定多个名称-值参量。ch = mlreportgen.report.Chapter(PropertyName=Value)
属性
章节标题,指定为以下值之一:
字符向量或字符串标量
DOM 对象
1×N 或 N×1 字符串标量或 DOM 对象数组
1×N 或 N×1 字符串标量、字符向量和 DOM 对象的元胞数组
getTitleReporter方法返回的mlreportgen.report.Title对象
标题出现在章节的开头以及除第一页之外的所有章节页面的页眉中。该标题也出现在报告的目录中。
内联对象是段落可以包含的对象。如果标题值是内联对象,则 Chapter 对象将使用其模板库中的模板根据该值创建标题。创建标题所用的模板取决于标题是否编号。章节标题默认是有编号的。要关闭本章节的编号,请使用 Numbered 属性。要关闭报告中所有其他章节的编号,请使用 mlreportgen.report.Section.number 方法。
如果标题有编号,则在英文报告中标题会以 Chapter N 形式的字符串作为前缀,其中 N 是自动生成的章节编号。在某些其他语言环境中,英语前缀会被翻译为该语言环境的语言。请参阅 mlreportgen.report.Report 的 Locale 属性以获取翻译语言环境的列表。
您可以使用内联 DOM 对象来覆盖章节默认标题模板指定的字符格式。
如果标题值是 DOM 段落或其他 DOM 模块对象,则章节会将该对象插入到章节的开头。如果使用 DOM 模块对象,则可以使用模块元素自定义章节标题的间距、对齐方式和其他属性。在这种情况下,您必须自己完整指定标题格式并提供标题编号。
注意
为了使页眉正确显示标题,标题的样式名称必须为 SectionTitle1。如果标题指定为 DOM mlreportgen.dom.Paragraph 对象且未设置 StyleName,则 StyleName 属性会自动更改为正确的样式名称。您可以通过在 Paragraph 对象的 Style 属性中包含 DOM 样式对象来自定义段落样式。如果您使用自定义模板来格式化标题,请确保模板使用的样式名称是 SectionTitle1。通过修改自定义模板中的 SectionTitle1 样式来自定义标题样式。
属性:
GetAccess | public |
SetAccess | public |
是否为本章节编号,指定为逻辑值 1 (true) 或 0 (false)。当您指定:
[]或1- 根据报告中其他章节的顺序为该章节编号。章节编号出现在标题中。0- 不要给本章节编号。
Numbered 属性的值将覆盖 mlreportgen.report.Chapter.number 方法为所有报告章节指定的编号。
属性:
GetAccess | public |
SetAccess | public |
数据类型: logical
此节的内容,指定为以下值之一:
字符向量或字符串标量
可以添加到 DOM 文档部件的 DOM 对象
报告器,包括
Section报告器1x N 或 N x1 字符串标量或字符向量数组
1x N 或 N x1 由字符串标量、字符向量和 DOM 对象组成的元胞数组
使用 Chapter 构造函数或 append 方法来设置此属性。您不能直接设置它。
属性:
GetAccess | public |
SetAccess | public |
本章的布局,指定为 mlreportgen.report.ReporterLayout 对象。使用 ReporterLayout 对象的属性来覆盖章节模板中定义的一些章节布局属性。
示例: chapter.Layout.Landscape = true
属性:
GetAccess | public |
SetAccess | public |
该报告器的模板来源,以下列方式之一指定:
字符向量或字符串标量,指定包含此报告器模板的文件的路径
此报告器使用的模板或其模板库中包含此报告器模板的报告器或报告
文档对象模型 (DOM) 文档或文档部分,该报告器使用其模板或其模板库包含该报告器的模板
指定的模板必须与您追加此报告器的报告类型相同。例如,对于 Microsoft® Word 报告,TemplateSrc 必须是 Word 报告模板。如果 TemplateSrc 属性为空,则此报告器将使用默认报告器模板作为报告的输出类型。
属性:
GetAccess | public |
SetAccess | public |
NonCopyable | true |
Dependent | true |
此报告器的模板名称,指定为字符向量或字符串标量。该报告器的模板必须位于该报告器的 TemplateSrc 属性指定的模板的模板库中。
属性:
GetAccess | public |
SetAccess | public |
数据类型: char | string
此报告器的超链接目标,指定为指定链接目标 ID 的字符向量或字符串标量,或 mlreportgen.dom.LinkTarget 对象。字符向量或字符串标量值转换为 LinkTarget 对象。链接目标在输出报告中紧接着此报告器的内容。
属性:
GetAccess | public |
SetAccess | public |
方法
append | 向章节添加内容 |
add | (不推荐)向章节添加内容 |
getTitleReporter | 获取章节标题报告器 |
mlreportgen.report.Chapter.number | mlreportgen.report.Chapter.number(report,numbering) 指定是否对报告中的章节进行编号。如果 numbering 是 true,则报告中的所有章节都已编号。 |
mlreportgen.report.Chapter.createTemplate |
|
mlreportgen.report.Chapter.customizeReporter | mlreportgen.report.Chapter.customizeReporter(toClasspath) 创建一个从 Chapter 报告器类派生的空类,名称为 toClasspath。您可以使用生成的类作为创建 Chapter 报告器的自定义版本的起点。 |
mlreportgen.report.Chapter.getClassFolder | 获取包含 返回值
有关详细信息,请参阅 |
copy | 创建报告器对象的副本,并对属性值进行深拷贝 输入参量
返回值
有关详细信息,请参阅 |
getImpl | 获取报告器的实现 注意 调用此方法后,您无法再向报告器添加内容。 输入参量
返回值
有关详细信息,请参阅 |
示例
将节添加到章中,将章添加到报告。将章节的布局方向设置为横向。
import mlreportgen.report.* import mlreportgen.dom.* rpt = Report('My Report','pdf'); append(rpt,TitlePage(Title='My Report')); chapter = Chapter('Images'); chapter.Layout.Landscape = true; append(chapter,Section(Title='Boeing 747',Content=Image('b747.jpg'))); append(rpt,chapter); close(rpt); rptview(rpt);
这是生成的报告第 1 章的第一页。

版本历史记录
在 R2017b 中推出从 R2020b 开始,使用 append 方法(而不是 add 方法)向这些报告 API 类的对象添加内容:
mlreportgen.report.Reportmlreportgen.report.Chaptermlreportgen.report.Sectionslreportgen.report.Report
要向 DOM API 对象添加内容(例如 mlreportgen.dom.Paragraph 对象),请继续使用 DOM 对象的 append 方法。使用 append 向报告 API 对象添加内容的优势在于,您使用与向 DOM API 对象添加内容相同的方法名称。
没有计划删除 Report、Chapter 或 Section 类的 add 方法。使用 add 方法的报告 API 程序将继续运行。
要更新现有代码,请将方法名称 add 替换为 append,如表中示例所示。
| 不推荐 | 推荐 |
|---|---|
import mlreportgen.report.* import mlreportgen.dom.* rpt = Report("My Report","pdf"); ch = Chapter("My Chapter"); sect = Section("My Section"); para = Paragraph("My Content "); append(para,"more Content"); add(sect,para); add(ch,sect); add(rpt,ch); close(rpt); rptview(rpt); | import mlreportgen.report.* import mlreportgen.dom.* rpt = Report("My Report","pdf"); ch = Chapter("My Chapter"); sect = Section("My Section"); para = Paragraph("My Content "); append(para,"more Content"); append(sect,para); append(ch,sect); append(rpt,ch); close(rpt); rptview(rpt); |
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)