mlreportgen.dom.DocumentPart Class
Namespace: mlreportgen.dom
Create a document part object
Description
Define a document part, a repeatable part of a report. A document part typically has holes that you fill during report generation. You can append a part to a document or to a document part of the same output type.
The mlreportgen.dom.DocumentPart class is a handle class.
Creation
Description
documentPartObj = DocumentPart
documentPart = DocumentPart(type)
documentPartObj = DocumentPart(type,templatePath)
documentPartObj = DocumentPart(type,templatePath,docPartTemplateName)
documentPartObj = DocumentPart(templateSrc,docPartTemplateName)
Input Arguments
Type of output, specified as one of these values:
- "docx"for Microsoft Word
- "html"for HTML output
- "html-file"for single-file HTML output
- "html-multipage"for multipage HTML output (since R2024a)
- "pdf"for PDF output
- "pdfa"for PDF/A output (since R2025a)
If you specify a template using the templatePath
                            argument, the value for type must match the template
                            type.
Full path of this part’s template file or folder, specified as a
                            character vector or string scalar. If you omit a file extension, the
                            template type is based on the document type, for example,
                                .docx for Word.
Data Types: char
Document part template name, specified as a character vector or string
                            scalar. Specify where the part is stored using the
                                templatePath or templateSrc
                            argument.
Document or document part object whose template contains the template
                            for this document part, specified as an
                                mlreportgen.dom.Document object for a document or
                            an mlreportgen.dom.DocumentPart object for a document
                            part.
Properties
ID of the current hole in the document, specified as a character vector or string scalar.
Attributes:
| GetAccess | public | 
| SetAccess | private | 
| Transient | true | 
| NonCopyable | true | 
Data Types: char | string
Type of the current template hole, specified as "Inline" or
                                "Block".
- An inline hole is for document elements that a paragraph element can contain: - Text,- Image,- LinkTarget,- ExternalLink,- InternalLink,- CharEntity, or- AutoNumber.
- A block hole can contain a - Paragraph,- Table,- OrderedList,- UnorderedList,- DocumentPart, or- Groupelement.
Attributes:
| GetAccess | public | 
| SetAccess | private | 
| Transient | true | 
| NonCopyable | true | 
Data Types: char | string
Current page layout of this document, specified as an
                mlreportgen.dom.DOCXPageLayout object,
                mlreportgen.dom.PDFPageLayout object, or []. This
            property applies to Word and PDF documents. For Word documents, the value is a
                DOCXPageLayout object that specifies the current page layout. For
            PDF documents, the value is a PDFPageLayout object if the document
            currently specifies a page layout. For HTML documents, the value is always
                [].
Attributes:
| GetAccess | public | 
| SetAccess | private | 
| Transient | true | 
| NonCopyable | true | 
Open status of this document, specified as "unopened",
                "open", or "closed".
Attributes:
| GetAccess | public | 
| SetAccess | private | 
| Transient | true | 
| NonCopyable | true | 
Data Types: char | string
The name of this part's template if the template is stored in the document
                        part template library of the template specified by this part"s
                            TemplatePath property, specified as a string scalar
                        or a character vector. If this property is [], the template specified by the
                            TemplatePath property is used as this part's
                        template.
Attributes:
| GetAccess | public | 
| SetAccess | public | 
| NonCopyable | true | 
Data Types: char
Path of this part"s template or of a template whose template library contains this part's template, specified as a character vector or string scalar.
Attributes:
| GetAccess | public | 
| SetAccess | public | 
| NonCopyable | true | 
Data Types: char
Output file type, specified as one of these values:
| Value | File Type | 
|---|---|
| "docx" | Microsoft Word | 
| "html" | HTML output as a zipped or unzipped folder containing the HTML document text, image, style sheet, and JavaScript® files | 
| "html-file" | HTML output consisting of a single file that contains the text, style sheets, JavaScript, and images for the report | 
| "html-multipage"(since R2024a) | HTML output as a zipped or unzipped folder containing the HTML document text divided into multiple pages, image, style sheet, and JavaScript files | 
| "pdf" | |
| "pdfa"(since R2025a) | PDF/A | 
If you specify a template using the TemplatePath property, the
            template must be consistent with the Type property.
Attributes:
| GetAccess | public | 
| SetAccess | public | 
| NonCopyable | true | 
Data Types: char | string
Parent of this object, specified as a document element object. A document element must have only one parent.
Attributes:
| GetAccess | public | 
| SetAccess | private | 
| NonCopyable | true | 
Children of this object, specified as an array of document element objects. This
            property contains the document element objects appended using the
                append method.
Attributes:
| GetAccess | public | 
| SetAccess | private | 
| NonCopyable | true | 
Tag, specified as a character vector or string scalar. The DOM API generates a
            session-unique tag as part of the creation of this object. The generated tag has the
            form CLASS:ID, where
                    CLASS is the object class and
                    ID is the value of the
                Id property of the object. Use this value to help identify
            where an issue occurs during document generation.
Attributes:
| GetAccess | public | 
| SetAccess | public | 
| NonCopyable | true | 
Data Types: char | string
Object identifier, specified as a character vector or string scalar. The DOM API generates a session-unique identifier when it creates the document element object.
Attributes:
| GetAccess | public | 
| SetAccess | public | 
| NonCopyable | true | 
Data Types: char | string
Methods
Use DocumentPart methods like you use the
                corresponding Document methods.
| Method | Purpose | 
|---|---|
| Use
                                         | Append HTML text to document part | 
| Use
                                         | Append HTML file contents to document part | 
| Append document element to the document part. | |
| Close this document part. You cannot close a document part if it has not been opened or was previously closed. | |
| Create document part template. | |
| Fill document part hole. | |
| Get core properties of document part. | |
| Get full path of main part of output document. | |
| Move to next template hole. | |
| Open this document part. You cannot open a document part if it was previously opened or closed. You also cannot open a document part if its library source is closed. | |
| Set core properties of document part. | 
Examples
This example creates a function
                        createMagicSquareReport that defines a document part
                    based on a blank document part template. The new document part has a heading
                    whose text depends on the input. Each document part generated contains a magic
                    square table whose appearance is also based on the input. The example also
                    creates a local function createSquareSection that appends the
                    document part to the report iteratively based on the input.
Create the function.
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";
Call the function to generate the report. Change the input arguments to change the contents or output format. This example creates a Word document that contains three squares.
 createMagicSquareReport([5,8,12],"docx");Version History
Introduced in R2014aYou can output DOM and Report API reports in the PDF/A format.
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.
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)