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.HTMLFile class

Package: mlreportgen.dom
Superclasses:

Convert an HTML file to a DOM document

Description

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

Construction

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
brn/a
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 www.w3schools.com/tags.

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 www.w3schools.com/cssref.

Input Arguments

expand all

HTML file path, specified as a character vector.

Properties

expand all

Note

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;
&Ampersand&amp;
"Double quotation mark&quot;
'Single quotation mark&apos;
%Percent&#37;

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.

Methods

appendAppend HTML to HTMLFile object

Examples

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:14pt;}</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>

Run these commands to convert the myHTMLReport.html file to a Word report.

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

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

Introduced in R2015a

Was this topic helpful?