Desktop User Guides > Professional > Table scripting > Exporting tables > HTML tables export > HTML tables export: Working with the HTML Export Render Object
 
HTML tables export: Working with the HTML Export Render Object
Sample script file: ExportHtmlRender.mrs
This example script is based on the Museum sample data set. See Running the sample table scripts for information on running the example scripts.
You might want to export your TOM document to HTML, with the output including both tables and charts. The HTML Export Render component exports your tables and charts to HTML. Instead of using a properties XML file, you can use the IRender interface properties to customize the output. You can also use the IRender interface to export tables into a HTML string; the HTML string can then be inserted in an existing HTML page.
The following sample script exports Museum tables to HTML. You can change the MDD_FILE and XML_FILE values if you want to use the other MetaData and CaseData files. EXPORT_FILE is location of the output file.
'Define constants for file locations used in the script
Const MDD_FILE = "C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Data\Xml\Museum.mdd"
Const XML_FILE = "C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Data\Xml\Museum.xml"
Const EXPORT_FILE = "C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Output\Test.html"
The following script creates and populates the tables. After loading and populate the tables, you can generate the tables XML string via the TOM Document method. See Table Object Model reference for more information.
Dim TableDoc, TableXML
' Create the Table Document object
Set TableDoc = CreateObject("TOM.Document")
' Load the Museum sample XML data set
TableDoc.DataSet.Load(MDD_FILE, , XML_FILE, "mrXmlDsc")
' ---- Create the tables ----
With TableDoc.Tables
  .AddNew("Table1", "age * gender", "Age by Gender")
  .AddNew("Table2", "Distance", "Distance from home to museum")
  .AddNew("Table3", "before * distance", "Before by Distance")
End With
' ---- Populate the tables ----
TableDoc.Populate()
TableXML = TableDoc.GetTablesXml("Table1, Table2, Table3", 1)
The following script allows you to create an ExportHtml.Renderer object and export the tables.
' ---- Load Export Component ----
Dim HtmlRender, HtmlOut
Set HtmlRender = CreateObject("ExportHtml.Renderer")
HtmlRender.DisplayAnnotations = False
HtmlRender.DisplayOption = 0
HtmlRender.EmbedCss = False
HtmlRender.UseFormattedLabels = True
HtmlRender.IncludeTitleBlock = False
HtmlRender.IncludeTOC = False
HtmlRender.OutputBodyOnly = True
HtmlOut = HtmlRender.Render(TableXML)
In this example, HtmlOut renders the export tables as an HTML string. You can retrieve the HTML string via Debug.log(HtmlOut), and then insert the exported results into an existing HTML page. If you want to export the tables directly to an HTML file, you can define the save location by using the HtmlRender.Destination property value. For example:
HtmlRender.Destination = EXPORT_FILE
HtmlRender.Render(TableXML, EXPORT_FILE)
See also
HTML tables export