Create Report Containers
Create Report API Objects to Hold Content
Every Report API program must create an mlreportgen.report.Report
object to hold report content. Use the mlreportgen.report.Report
constructor to create a Report object.
If you use the constructor without arguments, the constructor creates a PDF
document named untitled.pdf in the current folder. To specify a
name and location, use the path name of the report as the first argument of the
constructor.
You can specify the type of report to generate by using the
type argument. You can specify the type as:
"docx"— Microsoft® Word document."html"— HTML report, packaged as a zipped file that contains the HTML file, images, style sheet, and JavaScript® files of the report. To generate an HTML report as a folder that contains unzipped files, set thePackageTypeproperty to"unzipped"or"both"."html-file"— HTML report that consists of a single HTML file that contains the text, style sheets, JavaScript, and base64-encoded images of the report."pdf"— PDF file."pdfa"— PDF/A file. (since R2025a)
This Report constructor creates a document object called
myReport for Word output.
d = Report("myReport","docx");
Using the templatePath argument, you can specify the path name
of a custom template to use as a basis for formatting the report. Specify a template
path if you want to base your report on a custom template that defines the
appearance and structure of your report. The template type must match the document
type. For example, this report constructor creates a report object for Word output
using the template myWordTemplate.dotx.
d = Report("myReport","docx","myWordTemplate");
Create DOM Document Objects to Hold Content
If you intend to use the DOM API alone (i.e., without using Report API objects) to
generate a report, you must create an mlreportgen.dom.Document object
to hold the report content. Use the mlreportgen.dom.Document
constructor to create a Document object.
If you use the constructor without arguments, the DOM API creates an HTML document
named Untitled.htmx in the current folder. To specify a name and
location, use the path name of the report as the first argument of the
constructor.
You can specify the type of report to generate by using the
type argument. You can specify the type as:
"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)
This Document constructor creates a document object called
myReport for Word output.
d = Document("myReport","docx");
Using the templatePath argument, you can specify the path name
of the template to use as a basis for formatting the report. Specify a template path
if you want to base your report on a custom template that defines the appearance and
structure of your report. The template type must match the document type. For
example, this Document constructor creates a document object for
Word output using the template myWordTemplate.dotx.
d = Document("myReport","docx","myWordTemplate");