mlreportgen.dom.DocumentPart 类
命名空间: mlreportgen.dom
创建文档部件对象
描述
定义文档部件,报告中可重复的部分。文档部件通常存在一些空位,您需要在报告生成期间填充这些空位。您可以将某个部分追加到文档或相同输出类型的文档部件。
mlreportgen.dom.DocumentPart
类是一个 handle
类。
创建对象
描述
使用默认 HTML 模板创建 HTML 文档部件。 documentPartObj
= DocumentPart
根据指定的模板创建文档部件。documentPartObj
= DocumentPart(type
,templatePath
)
根据指定模板中的指定文档部件模板创建文档部件。documentPartObj
= DocumentPart(type
,templatePath
,docPartTemplateName
)
根据存储在指定源使用的模板中的指定文档部件模板创建文档部件。源可以是文档或文档部件。documentPartObj
= DocumentPart(templateSrc
,docPartTemplateName
)
输入参量
type
— 输出的类型
"html"
(默认) | "docx"
| "pdf"
| "html-file"
| "html-multipage"
输出的类型,指定为下列值之一:
"html"
- HTML 输出"pdf"
- 基于 PDF 模板的 PDF"docx"
- Word 输出"html-file"
- HTML 输出,使用包含报告的 CSS、JavaScript® 和图像的单个文件"html-multipage"
- HTML 输出包含 HTML 文档文本,分为页面、图像、样式表和 JavaScript 文件 (自 R2024a 起)
如果使用 templatePath
参量指定模板,则 type
的值必须与模板类型匹配。
templatePath
— 此部件模板的路径
[]
(默认值) | 字符向量 | 字符串标量
此部件的模板文件或文件夹的完整路径,指定为字符向量或字符串标量。如果省略文件扩展名,则模板类型基于文档类型,例如 Word 的 .docx
。
数据类型: char
docPartTemplateName
— 文档部件模板名称
字符向量 | 字符串标量
文档部件模板名称,指定为字符向量或字符串标量。使用 templatePath
或 templateSrc
参量指定该部件的存储位置。
templateSrc
— 包含文档部件模板的文档或文档部件
mlreportgen.dom.Document
对象 | mlreportgen.dom.DocumentPart
对象
文档或文档部件对象,其模板包含此文档部件的模板,指定为文档的 mlreportgen.dom.Document
对象或文档部件的 mlreportgen.dom.DocumentPart
对象。
属性
CurrentHoleId
— 文档中当前空位的 ID
''
(默认) | 字符向量 | 字符串标量
文档中当前空位的 ID,指定为字符向量或字符串标量。
属性:
SetAccess | private |
Transient | true |
NonCopyable | true |
数据类型: char
| string
CurrentHoleType
— 当前空位类型
''
(默认) | "Inline"
| "Block"
当前模板空位的类型,指定为 "Inline"
或 "Block"
。
内联空位适用于段落元素可以包含的文档元素:
Text
、Image
、LinkTarget
、ExternalLink
、InternalLink
、CharEntity
或AutoNumber
。块状空位可以包含
Paragraph
、Table
、OrderedList
、UnorderedList
、DocumentPart
或Group
元素。
属性:
SetAccess | private |
Transient | true |
NonCopyable | true |
数据类型: char
| string
CurrentPageLayout
— 本文档的当前页面布局
[]
(默认) | mlreportgen.dom.DOCXPageLayout
对象 | mlreportgen.dom.PDFPageLayout
对象 | []
该文档的当前页面布局,指定为 mlreportgen.dom.DOCXPageLayout
对象、mlreportgen.dom.PDFPageLayout
对象或 []
。此属性适用于 Word 和 PDF 文
档。对于 Word 文档,该值是一个指定当前页面布局的 DOCXPageLayout
对象。对于 PDF 文档,如果文档当前指定了页面布局,则该值为 PDFPageLayout
对象。对于 HTML 文档,该值始终为 []
。
属性:
SetAccess | private |
Transient | true |
NonCopyable | true |
OpenStatus
— 文档元素的打开状态
'unopened'
(默认) | 'open'
| 'closed'
该文档的打开状态,指定为 'unopened'
、'open'
或 'closed'
。
属性:
SetAccess | private |
Transient | true |
NonCopyable | true |
数据类型: char
| string
TemplateName
— 此部件模板的名称
''
(默认) | 字符向量 | 字符串标量
如果模板存储在此部件的 TemplatePath
属性指定的模板的文档部件模板库中,则此部件的模板名称指定为字符串标量或字符向量。如果此属性为 [],则使用 TemplatePath
属性指定的模板作为此部件的模板。
属性:
NonCopyable | true |
数据类型: char
TemplatePath
— 模板路径
字符向量 | 字符串标量
此部件模板的路径或模板库包含此部件模板的模板的路径,指定为字符向量或字符串标量。
属性:
NonCopyable | true |
数据类型: char
Type
— 输出文件类型
"html"
(默认) | "docx"
| "html-file"
| "html-multipage"
| "pdf"
输出文件类型,指定为以下值之一:
值 | 文件类型 |
---|---|
"docx" | Microsoft Word |
"html" | HTML 输出为压缩或解压后的文件夹,其中包含 HTML 文档文本、图像、样式表和 JavaScript 文件 |
"html-file" | HTML 输出由单个文件组成,其中包含报告的文本、样式表、JavaScript 和图像 |
"html-multipage" (自 R2024a 起) | HTML 输出为压缩或解压后的文件夹,其中包含分为多个页面的 HTML 文档文本、图像、样式表和 JavaScript 文件 |
"pdf" |
如果使用 TemplatePath
属性指定模板,则该模板必须与 Type
属性一致。
属性:
NonCopyable | true |
数据类型: char
| string
Parent
— mlreportgen.dom.DocumentPart
对象的父级
文档元素对象
mlreportgen.dom.DocumentPart
对象的父级,指定为文档元素对象。一个文档元素必须只有一个父元素。
属性:
SetAccess | private |
NonCopyable | true |
Children
— mlreportgen.dom.DocumentPart
对象的子级
文档元素对象数组
mlreportgen.dom.DocumentPart
对象的子项,指定为文档元素对象的数组。此属性包含使用 append
方法追加的文档元素对象。
属性:
SetAccess | private |
NonCopyable | true |
Tag
— mlreportgen.dom.DocumentPart
对象的标签
字符向量 | 字符串标量
mlreportgen.dom.DocumentPart
对象的标签,指定为字符向量或字符串标量。DOM API 在创建此对象的过程中生成一个会话唯一标签。生成的标签形式为 CLASS:ID
,其中 CLASS
是对象类,ID
是对象的 Id
属性的值。指定您自己的标签值,以帮助您确定在文档生成过程中出现问题时要查找的位置。
属性:
NonCopyable | true |
数据类型: char
| string
Id
— mlreportgen.dom.DocumentPart
对象的标识符
字符向量 | 字符串标量
mlreportgen.dom.DocumentPart
对象的对象标识符,指定为字符向量或字符串标量。DOM API 在创建文档元素对象时会生成一个会话唯一标识符。您可以为 Id
指定自己的值。
属性:
NonCopyable | true |
数据类型: char
| string
方法
公共方法
使用 DocumentPart
方法就像使用相应的 Document
方法一样。
方法 | 用途 |
---|---|
| 将 HTML 文本追加到文档部件 |
| 将 HTML 文件内容追加到文档部件 |
将文档元素追加到文档部件。 | |
关闭此文档部件。如果文档部件尚未打开或者之前已关闭,则您无法关闭它。 | |
创建文档部件模板。 | |
填补文档部件空位。 | |
获取文档部件的核心属性。 | |
获取输出文档主体部分的完整路径。 | |
移至下一个模板空位。 | |
打开此文档部件。如果文档部件先前已打开或关闭,则您无法打开它。如果库源已关闭,您也无法打开文档部件。 | |
设置文档部件的核心属性。 |
示例
空白文档部件模板中的文档部件
此示例创建一个函数 createMagicSquareReport
,该函数根据空白文档部件模板定义文档部件。新文档部件有一个标题,其文本取决于输入。生成的每个文档部件都包含一个幻方表,其外观也基于输入。该示例还创建了一个本地函数 createSquareSection
,该函数根据输入迭代地将文档部件追加到报告中。
创建函数。
function createMagicSquareReport(square_sizes, report_type) %createMagicSquareReport Report on magic squares % magic_square_report(square_sizes, report_type) % creates a report of the specified output type % (docx, pdf, or html) on the specified magic % squares. For example, to create a PDF report on % squares of size 5, 10, and 15, enter the following % line at the MATLAB command line: % % createMagicSquareReport([5,10,15],"pdf"); import mlreportgen.dom.*; rpt = Document("MagicSquareReport",report_type); open(rpt); for i = 1:length(square_sizes) sz = square_sizes(i); section = createSquareSection(rpt,sz); append(rpt,section); end close(rpt); rptview(rpt.OutputPath); function section = createSquareSection(rpt,square_size) import mlreportgen.dom.*; % Create document part to hold section section = DocumentPart(rpt.Type); % Create magic square heading h1 = Heading1(sprintf("magic(%i)",square_size)); % Put each square on a separate page. h1.Style = {PageBreakBefore(true)}; append(section,h1); % Create table to hold square table = append(section, Table(magic(square_size))); % Format table table.Border = "solid"; table.ColSep = "solid"; table.RowSep = "solid";
调用该函数来生成报告。改变输入参量来改变内容或输出格式。本示例创建一个包含三个正方形的 Word 文档。
createMagicSquareReport([5,8,12],"docx");
版本历史记录
在 R2014a 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)