Main Content

addHTMLFile

Class: mlreportgen.dom.Document
Namespace: mlreportgen.dom

Append HTML file contents to document

Syntax

htmlObjOut = addHTMLFile(documentObj,htmlFilePath)

Description

htmlObjOut = addHTMLFile(documentObj,htmlFilePath) appends HTML file contents to a document.

Input Arguments

expand all

Document object to append content to, specified as an mlreportgen.dom.Document object.

HTML file path, specified as a character vector.

Output Arguments

expand all

HTML object with appended content, returned as an mlreportgen.dom.HTMLFile object.

Examples

expand all

In a text editor, create a file and enter this text:

<!DOCTYPE html>
<html>

<head>
  <title>My First HTML</title>
 
</head>

<body>

<p>This is the <b>first</b> paragraph.</p>

<p>This is the <b>second</b> paragraph</p>

</body>
</html>

Save the file in the MATLAB® current folder as html_example.html.

Create a Word report.

import mlreportgen.dom.*;
rpt = Document('HTMLReport','docx');     

Append the HTML file content to the document.

addHTMLFile(rpt,'html_example.html');

Generate the Word report.

close(rpt);
rptview(rpt.OutputPath);

Tips

  • MATLAB Report Generator™ mlreportgen.dom.HTML or mlreportgen.dom.HTMLFile objects typically cannot accept the raw HTML output of third-party applications, such as Microsoft® Word, that export native documents as HTML markup. In these cases, your Report API report generation program can use the mlreportgen.utils.html2dom.prepHTMLString and mlreportgen.utils.html2dom.prepHTMLFile functions to prepare the raw HTML for use with the mlreportgen.dom.HTML or mlreportgen.dom.HTMLFile objects. Typically, your program will have to further process the prepared HTML to remove valid but undesirable objects, such as line feeds that were in the raw content.

  • By default, the DOM API uses a base font size of 12 points to convert em units to actual font sizes. For example, a font size specified as 2em converts to 24 points. To specify a different base font size, add your content to a report by using an mlreportgen.dom.HTML object. Set the EMBaseFontSize property of the object to the base font size. For example, if you set the EMBaseFontSize property to 14, a font size of 2em converts to 28 points.

Version History

Introduced in R2015a