Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

mlreportgen.dom.Document class

Package: mlreportgen.dom
Superclasses:

Document container

Description

Create mlreportgen.dom.Document object that defines:

  • The type of output: HTML, Microsoft® Word, or PDF.

  • Where and how to store the output.

  • The template to use to format the document.

Construction

documentObj = Document() creates an HTML document named Untitled.htmx in the current directory, using the default HTML template.

Append content and use a corresponding close command to generate the document.

documentObj = Document(outputPath) creates an HTML document at the specified location.

documentObj = Document(outputPath,type) creates a document of the specified type (for example, Word), using the default template for that type.

documentObj = Document(outputPath,type,templatePath) creates a document, using the specified document type and Word, PDF, or HTML template corresponding to the type setting.

Input Arguments

expand all

Full path of output file or folder for this document. If you do not specify a file extension, the extension is based on the document type (for example, .docx for Microsoft Word). You can set this property only before opening the document.

How you specify the path depends on the value of the PackageType property.

  • 'zipped' — Name of zip file.

  • 'unzipped' — Folder for the output files.

  • 'both' — Name of zip file.

Data Types: char

Type of output, specified as 'html', 'docx', 'pdf', or 'html-file'.

  • 'html'— HTML output as a zipped or unzipped folder containing the HTML document text, image, style sheet, and JavaScript® files.

  • 'docx'— Word output.

  • 'pdf'— PDF document based on a PDF template.

  • 'html-file'— HTML output consisting of a single file that contains the text, style sheets, JavaScript, and images for the report

If you specify a template using the templatePath input argument, the template must be consistent with the type argument.

Full path of a custom template file or folder, specified as a character vector. If you omit a file extension, the template type is based on the document type, for example, .docx for Word.

Data Types: char

Output Arguments

expand all

Report definition document, represented by an mlreportgen.dom.Document object.

Properties

expand all

This read-only property lists child elements of this object.

This read-only property is the hole ID of the current hole in this document.

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, AutoNumber.

  • A block hole can contain a Paragraph, Table, OrderedList, UnorderedList, DocumentPart, or Group.

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 [].

Set this property to true to overwrite an existing output file of the same name for a report from this document. If this property is false and a writable file of the same name exists, attempting to close (i.e., write) this document causes an error. If the existing file is read-only, closing this document causes an error regardless of the setting of this property.

Data Types: logical

Custom content for HTML header, specified as a character vector. The value of this property is appended to the <head> element of this document after the content specified by the head section of the document's template. Set this property only before opening the document.

ID for this document element, specified as a character vector. The DOM generates a session-unique ID when it creates the document element. You can specify your own ID.

This read-only property lists the open status of this document element.

Path of this document's output file, specified as a character vector. If you do not specify the file extension, the DOM adds an extension based on the output type of the document. You can set this property only before opening the document.

For unzipped output packaging, the path specifies the folder for the output files. The default is the current folder.

Packaging for output files, specified as one of these values:

  • 'zipped' — Applies only to Word and multifile HTML output

  • 'unzipped' — Applies only to Word and multifile HTML output

  • 'both' — Applies only to Word and multifile HTML output

  • 'single-file' — Creates the report as a single file. This value appears if you set the document’s Type property to 'pdf' or 'html-file'. You cannot set or change this value yourself.

For zipped packaging, the document output is a zip file located at the location specified by the OutputPath property. The zip file has the extension that matches the document type: docx for Word output or htmtx for HTML output. For example, if the document type is docx and OutputPath is s:\docs\MyDoc, the output is packaged in a zip file named s:\docs\MyDoc.docx.

For unzipped packaging, the document output is stored in a folder having the root file name of the OutputPath property. For example, if the OutputPath is s:\docs\MyDoc, the output folder is s:\docs\MyDoc.

If you set PackageType to both, generating the report produces zipped and unzipped output.

This read-only property lists the parent of this document element.

By default, document elements are stored in memory until the document is closed. Set this property to true to write document elements to disk as the elements are appended to the document.

Data Types: logical

Tag for this document, in the form CLASS:ID, where CLASS is the document class and ID is the value of the Id property of the object. You can specify a custom tag as a character vector.

An example of a reason for specifying your own tag value is to make it easier to identify where an issue occurred during document generation.

Data Types: char

The full path to the template to use, specified as a character vector.

For HTML documents, this property specifies the text that appears in the title bar of the browser used to display this document. Word and PDF documents ignore this property.

Set this property before opening the document for output.

Type of output, specified as 'html', 'docx', 'pdf', or 'html-file'.

  • 'html' — HTML output as a zipped or unzipped folder containing the HTML document text, image, style sheet, and JavaScript files.

  • 'docx' — Word output.

  • 'pdf' — PDF output.

  • 'html-file' — HTML output consisting of a single file that contains the text, style sheets, JavaScript, and images for the report.

If you specify a template using the TemplatePath property, the template must be consistent with the Type argument. You must specify a Word template (.dotx) for docx output, an HTML template package (.htmtx) for HTML output, a PDF template package (.pdftx) for PDF output, and a single-file HTML template (.htmt) for html-file output.

Methods

Method

Purpose

addHTML

Append HTML text to document

addHTMLFile

Append HTML file contents to document

append

Append document element to the document.

close

Close this document. You cannot close a document if it has not been opened or was previously closed.

createAutoNumberStream

Create automatically generated numbering stream.

createTemplate

Create document template.

fill

Fill document hole.

getAutoNumberStream

Get the automated numbering stream.

getCoreProperties

Get core properties of document.

getMainPartPath

Get relative path of main part of output document.

getOPCMainPart

Get full path of main part of output document.

moveToNextHole

Move to next template hole.

open

Open this document. You cannot open a document if it was previously opened or closed.

package

Append file to OPC package of document.

setCoreProperties

Set core properties of document element.

Examples

expand all

Create a Word document, add content, and view the report in Word.

import mlreportgen.dom.*;
d = Document('mydoc','docx');

append(d,'Hello World');

close(d);
rptview(d.OutputPath);

Create an HTML document as a single HTML file that includes the images of the document. The example assumes that there is a MyImage.jpg image and a myHTMLTemplate.htmt HTML template file.

Create a document whose output is a single HTML file and uses the template myHTMLTemplate. Add text and an image to the report. Close the document and view it.

import mlreportgen.dom.*;
d = Document('mydoc','html-file','myHTMLTemplate'); 
open(d); 

append(d,'Hello world'); 
append(d,Image('C:/images/LocalSystem/MyImage.jpg'));

close(d); 
rptview(d.OutputPath); 
Was this topic helpful?