Knowledge Base

T4 tags: Convert Excel to HTML

Last Modified:
22 May 2019
User Level:
Power User


This tag takes an Excel spreadsheet in the Media Library and publishes the data within that file as an HTML table on the page. The Excel to HTML tag is added to a Content Layout (to create the table) and to a Page Layout (to format the table) and content is added to the site using the Content Type.

There's more than one way to integrate external data in TERMINALFOUR and the method you choose can depend on the type of data and what you want to do with it.

Content Layout tag

For the example we are using a very basic spreadsheet:

Create a Content Type with a media element. In the Content Layout, add the tag. There are two attributes for this tag:

name Name of the media element in the content type that contains the Excel file.
output-sheet-name Setting this attribute to true will output the Excel sheet names. If this attribute is not included in the tag, sheet names will not be output on the page.


<t4 type="exceltohtml" name="media-file" />

<t4 type="exceltohtml" name="media-file" output-sheet-name="true" />

The output generated would be:

<div id="excel-285-media-file">
<div id="table-285-1-media-file">
<table class="excel-285-media-t1">
<col width="144">
<col width="144">
<col width="56">
<tr class="excel-285-media-r1">
<td class="excel-285-media-c1">Fruit</td>
<td class="excel-285-media-c1">Vegetables</td>
<td class="excel-285-media-c1"> </td>
<tr class="excel-285-media-r1">
<tr class="excel-285-media-r1">
<tr class="excel-285-media-r1">

Page Layout tag

A tag is added to the header of the Page Layout within the <style type="text/css"> tag in the header.

name Name of the media element in the Content Type that contains the Excel file.

If set, this allows a font-family and font-size to be configured and used for all tables in the Excel spreadsheet.

sheet-numbers-element if set, this allows specific sheets in the Excel spreadsheet to be published to the page. By default, all sheets within the Excel file are published onto the page. To specify the sheets to be published, create a plain text element in the content type (for example, called "Sheet Numbers") and specify this element name in the sheet-numbers-element attribute. When adding the content using this template the ‘Sheet Numbers’ element should be populated with a comma separated list of sheet numbers example: 1,3,4,


<style type="text/css">
<t4 type="exceltohtml" name="media-file" default-font="font-family:arial;font-size:8pt;" sheet-numbers-element="Sheet Numbers" />

  The output generated would be:

<style type="text/css">
.excel-285-media-c1{white-space: pre-wrap; text-align: left; vertical-align: bottom; font-weight: bold; color: black; font-family:arial;font-size:8pt; }


  • If a title is in one cell in the Excel file, it appears in one cell in the HTML table. If you want a title to span over more than one column in the HTML table then cells must be merged in the Excel file.
  • Rows merged in an Excel file can cause problems as there is no way to merge rows in a HTML table. The formatting of these rows must be corrected before they is displayed in the HTML correctly.