This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

mlreportgen.dom.HTMLFile class

Package: mlreportgen.dom

Convert an HTML file to a DOM document


Converts the contents of an HTML file to an HTMLFile object containing DOM objects having the same content and format.


htmlFileObj = HTMLFile(htmlFile) converts the HTML file to an HTMLFile object containing DOM objects having the same content and format.

An HTMLFile object supports these HTML elements and attributes. In addition, HTMLFile objects accept HTML that contains custom CSS properties, which begin with a hyphen. Custom CSS properties are supported in HTML, Microsoft® Word, and PDF output.

HTML ElementAttributes
aclass, style, href, name
bclass, style
bodyclass, style
codeclass, style
delclass, style
divclass, style
fontclass, style, color, face, size
h1, h2, h3, h4, h5, h6class, style, align
hrclass, style, align
iclass, style
insclass, style
imgclass, style, src, height, width, alt
liclass, style
olclass, style
pclass, style, align
preclass, style
sclass, style
spanclass, style
strikeclass, style
subclass, style
supclass, style
tableclass, style, align, bgcolor, border, cellspacing, cellpadding, frame, rules, width
tbodyclass, style, align, valign
tfootclass, style, align, valign
theadclass, style, align, valign
tdclass, style, bgcolor, height, width, colspan, rowspan, valign, nowrap
trclass, style, bgcolor, valign
ttclass, style
uclass, style
ulclass, style

For information about these elements, see the W3Schools tags documentation at

These CSS formats are supported:

  • background-color

  • border

  • border-bottom

  • border-bottom-color

  • border-bottom-style

  • boder-bottom-width

  • border-color

  • border-left

  • border-left-color

  • border-left-style

  • boder-left-width

  • border-right

  • border-right-color

  • border-rigtht-style

  • border-right-width

  • border-style

  • border-top

  • border-top-color

  • border-top-style

  • border-top-width

  • border-width

  • color

  • counter-increment

  • counter-reset

  • display

  • font-family

  • font-size

  • font-style

  • font-weight

  • height

  • line-height

  • list-style-type

  • margin

  • margin-bottom

  • margin-left

  • margin-right

  • margin-top

  • padding

  • padding-bottom

  • padding-left

  • padding-right

  • padding-top

  • text-align

  • text-decoration

  • text-indent

  • vertical-align

  • white-space

  • width

For information about these formats, see the W3Schools CSS documentation at

Input Arguments

expand all

HTML file path, specified as a character vector.


expand all


For HTML markup to display correctly in your report, you must include end tags for empty elements and enclose attribute values in quotation marks. If you want to show a reserved XML markup character as text, you must use its equivalent named or numeric XML character.

Reserved CharacterDescriptionEquivalent Character
>Greater than>
<Less than&lt;
"Double quotation mark&quot;
'Single quotation mark&apos;

A session-unique ID is generated as part of HTMLFile object creation. You can specify an ID to replace the generated ID.

Tag name of HTML container element, specified as a character vector, such as 'div', 'section', or 'article' corresponding to this HTMLFile object. This property applies only to HTML output.

This read-only property lists child elements that the HTMLFile object contains.

This read-only property lists the parent of this HTMLFile object.

Formatting to apply to the HTMLFile object, specified as a cell array of DOM format objects. The children of this HTMLFile object inherit any of these formats that they do not override.

Style name of this HTMLFile object, specified as a character vector. Use a name of a style specified in the style sheet of the document to which this HTMLFile object is appended. The specified style defines the appearance of the HTMLFile object in the output document where not overridden by the formats specified by this StyleName property of the HTMLFile object.

Tag for HTMLFile object, specified as a character vector.

A session-unique ID is generated as part of HTMLFile object creation. The generated tag has the form CLASS:ID, where CLASS is the class of the element and ID is the value of the Id property of the object. You can specify a tag to replace the generated tag.

Specify your own tag value, for example, to make it easier to identify where an issue occurred during document generation.


HTMLFile ignores the KeepInterElementWhiteSpace property. If you want to preserve white space, use fileread to read your HTML file as text and then follow the procedure described for the mlreportgen.dom.HTMLKeepInterElementWhiteSpace property.


appendAppend HTML to HTMLFile object


Convert HTML File to a Word Report

Create a text file named myHTMLReport.html and save it in the current folder. Add this text into the file:

<html> <head> <style>p {font-size:14 pt;}</style> </head> <body> <p style='white-space:pre'><b>Hello</b> <i style=''color:green''>World</i></p> <p>This is <u>me</u> speaking</p> </body> </html>

To convert the myHTMLReport.html file to a Word report, run these commands:

import mlreportgen.dom.*; 
rpt = Document('MyReport','docx'); 
htmlFile = HTMLFile('myHTMLReport.html'); 

The resulting Word report contains the text you specified in the HTML file.

Introduced in R2015a