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

Package: mlreportgen.dom
Superclasses:

Use HTML markup to create DOM document

Description

Converts a string of HTML markup to DOM objects and appends them to an HTML object that it also creates. You can append the HTML object to a DOM document of any type, including Word and PDF documents.

Construction

htmlObj = HTML() creates an empty HTML object.

htmlObj = HTML(htmlText) converts HTML text to an HTML object containing DOM objects having the same content and format.

An HTML object supports these HTML elements and attributes. In addition, HTML 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.

Input Arguments

expand all

HTML text, specified as a character vector

Example: html = HTML('<p><b>Hello</b> <i style="color:green">World</i></p>');

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

A session-unique ID is generated as part of HTML 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 HTML object. This property applies only to HTML output.

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

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

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

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

Tag for HTML object, specified as a character vector.

A session-unique ID is generated as part of HTML 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 string to HTML object
cloneCopy HTML 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?