Html export - export table html and css
Use the dropdowns to change table style and theme, then click the Reload button. This is the only roundtrip done back to EPPlus. Change the appearance of the table by checking/unchecking the checkboxes.
All CSS classes needed to style the table are exported from EPPlus and based on Excels table styles and themes. You can use the dev tools of your favorite browser to see how the classes are applied to the table.
Some selected parts of the model class for this page
public void SetupSampleData(int theme, TableStyles? style = TableStyles.Dark1)
{
// This method just fakes some data into a data table
InitDataTable();
using(var package = new ExcelPackage())
{
SetTheme(theme, package);
var sheet = package.Workbook.Worksheets.Add("Html export sample 1");
var tableRange = sheet.Cells["A1"].LoadFromDataTable(_dataTable, true, style);
// set number format for the BirthDate column
sheet.Cells[tableRange.Start.Row + 1, 4, tableRange.End.Row, 4].Style.Numberformat.Format = "yyyy-MM-dd";
tableRange.AutoFitColumns();
var table = sheet.Tables.GetFromRange(tableRange);
// table properties
table.ShowFirstColumn = this.ShowFirstColumn;
table.ShowLastColumn = this.ShowLastColumn;
table.ShowColumnStripes = this.ShowColumnStripes;
table.ShowRowStripes = this.ShowRowsStripes;
// Export Html and CSS
var exporter = table.CreateHtmlExporter();
exporter.Settings.Minify = false;
Css = exporter.GetCssString();
Html = exporter.GetHtmlString();
WorkbookBytes = package.GetAsByteArray();
}
}
private static void SetTheme(int theme, ExcelPackage package)
{
if (theme > 0)
{
var fileInfo = default(FileInfo);
switch (theme)
{
case 1:
fileInfo = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"themes\\Ion.thmx"));
break;
case 2:
fileInfo = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"themes\\Banded.thmx"));
break;
case 3:
fileInfo = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"themes\\Parallax.thmx"));
break;
default:
fileInfo = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"themes\\Ion.thmx"));
break;
}
package.Workbook.ThemeManager.Load(fileInfo);
}
}
public string Css { get; set; }
public string Html { get; set; }
Html as it was exported
<table class="epplus-table ts-dark1 ts-dark1-header" role="table">
<thead role="rowgroup">
<tr role="row">
<th data-datatype="string" class="epp-al" role="columnheader" scope="col">Country</th>
<th data-datatype="string" class="epp-al" role="columnheader" scope="col">FirstName</th>
<th data-datatype="string" class="epp-al" role="columnheader" scope="col">LastName</th>
<th data-datatype="datetime" class="epp-al" role="columnheader" scope="col">BirthDate</th>
<th data-datatype="string" class="epp-al" role="columnheader" scope="col">City</th>
</tr>
</thead>
<tbody role="rowgroup">
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Sophia</td>
<td role="cell">Gerlach</td>
<td data-value="615772800000" role="cell" class="epp-ar epp-s1">1989-07-07</td>
<td role="cell">Kunzeberg</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Ellsworth</td>
<td role="cell">Pollich</td>
<td data-value="463622400000" role="cell" class="epp-ar epp-s1">1984-09-10</td>
<td role="cell">Rueckermouth</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Eldora</td>
<td role="cell">Harber</td>
<td data-value="-585100800000" role="cell" class="epp-ar epp-s1">1951-06-18</td>
<td role="cell">South Ambermouth</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Lennie</td>
<td role="cell">Sipes</td>
<td data-value="-1512864000000" role="cell" class="epp-ar epp-s1">1922-01-23</td>
<td role="cell">West Laurelchester</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Etha</td>
<td role="cell">Blanda</td>
<td data-value="-1699228800000" role="cell" class="epp-ar epp-s1">1916-02-27</td>
<td role="cell">Bergeborough</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Rowland</td>
<td role="cell">Koch</td>
<td data-value="-2001888000000" role="cell" class="epp-ar epp-s1">1906-07-26</td>
<td role="cell">Lake Itzelfort</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Jakayla</td>
<td role="cell">Sipes</td>
<td data-value="559267200000" role="cell" class="epp-ar epp-s1">1987-09-22</td>
<td role="cell">Maryjanefurt</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Boris</td>
<td role="cell">Hahn</td>
<td data-value="-1526688000000" role="cell" class="epp-ar epp-s1">1921-08-16</td>
<td role="cell">D'Amoreburgh</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Ethyl</td>
<td role="cell">Swaniawski</td>
<td data-value="1398211200000" role="cell" class="epp-ar epp-s1">2014-04-23</td>
<td role="cell">Loweton</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Taryn</td>
<td role="cell">Koepp</td>
<td data-value="-819763200000" role="cell" class="epp-ar epp-s1">1944-01-10</td>
<td role="cell">Gwenbury</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Edyth</td>
<td role="cell">Moen</td>
<td data-value="1758499200000" role="cell" class="epp-ar epp-s1">2025-09-22</td>
<td role="cell">Sammyberg</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Delilah</td>
<td role="cell">Quigley</td>
<td data-value="-1217635200000" role="cell" class="epp-ar epp-s1">1931-06-02</td>
<td role="cell">Lomashire</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Walton</td>
<td role="cell">Ruecker</td>
<td data-value="-112665600000" role="cell" class="epp-ar epp-s1">1966-06-07</td>
<td role="cell">Lindseyfort</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Amber</td>
<td role="cell">Fadel</td>
<td data-value="1613779200000" role="cell" class="epp-ar epp-s1">2021-02-20</td>
<td role="cell">Sauermouth</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Dortha</td>
<td role="cell">Kuhn</td>
<td data-value="-1038355200000" role="cell" class="epp-ar epp-s1">1937-02-05</td>
<td role="cell">New Vestashire</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Ryleigh</td>
<td role="cell">Reinger</td>
<td data-value="-151545600000" role="cell" class="epp-ar epp-s1">1965-03-14</td>
<td role="cell">Colinfort</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Demetris</td>
<td role="cell">Waelchi</td>
<td data-value="-160012800000" role="cell" class="epp-ar epp-s1">1964-12-06</td>
<td role="cell">East Jaycee</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Summer</td>
<td role="cell">Hettinger</td>
<td data-value="-1741996800000" role="cell" class="epp-ar epp-s1">1914-10-20</td>
<td role="cell">Schoenfurt</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Robyn</td>
<td role="cell">Mosciski</td>
<td data-value="704851200000" role="cell" class="epp-ar epp-s1">1992-05-03</td>
<td role="cell">East Mohammedmouth</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Ruben</td>
<td role="cell">Welch</td>
<td data-value="-796435200000" role="cell" class="epp-ar epp-s1">1944-10-06</td>
<td role="cell">Karianebury</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Gabrielle</td>
<td role="cell">Pacocha</td>
<td data-value="-771379200000" role="cell" class="epp-ar epp-s1">1945-07-23</td>
<td role="cell">Joelbury</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Rafaela</td>
<td role="cell">Streich</td>
<td data-value="-920246400000" role="cell" class="epp-ar epp-s1">1940-11-03</td>
<td role="cell">East Abby</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Yolanda</td>
<td role="cell">Muller</td>
<td data-value="1317945600000" role="cell" class="epp-ar epp-s1">2011-10-07</td>
<td role="cell">Stromanborough</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Adeline</td>
<td role="cell">Shanahan</td>
<td data-value="-1502236800000" role="cell" class="epp-ar epp-s1">1922-05-26</td>
<td role="cell">East Laury</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Geovany</td>
<td role="cell">Fay</td>
<td data-value="-61171200000" role="cell" class="epp-ar epp-s1">1968-01-24</td>
<td role="cell">East Mallie</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Kendra</td>
<td role="cell">Bayer</td>
<td data-value="714009600000" role="cell" class="epp-ar epp-s1">1992-08-17</td>
<td role="cell">Lake Cary</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Mckayla</td>
<td role="cell">Fay</td>
<td data-value="-662169600000" role="cell" class="epp-ar epp-s1">1949-01-07</td>
<td role="cell">Marilouville</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Kathlyn</td>
<td role="cell">Willms</td>
<td data-value="546393600000" role="cell" class="epp-ar epp-s1">1987-04-26</td>
<td role="cell">Fernton</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Claudia</td>
<td role="cell">Herman</td>
<td data-value="1550707200000" role="cell" class="epp-ar epp-s1">2019-02-21</td>
<td role="cell">North Gussie</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Micah</td>
<td role="cell">Schiller</td>
<td data-value="337737600000" role="cell" class="epp-ar epp-s1">1980-09-14</td>
<td role="cell">Novaburgh</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Shemar</td>
<td role="cell">Blanda</td>
<td data-value="-118972800000" role="cell" class="epp-ar epp-s1">1966-03-26</td>
<td role="cell">Marianmouth</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Houston</td>
<td role="cell">Reichel</td>
<td data-value="-28944000000" role="cell" class="epp-ar epp-s1">1969-01-31</td>
<td role="cell">New Linnietown</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Neil</td>
<td role="cell">Block</td>
<td data-value="-812505600000" role="cell" class="epp-ar epp-s1">1944-04-03</td>
<td role="cell">East Theresia</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Eryn</td>
<td role="cell">Rowe</td>
<td data-value="-1610323200000" role="cell" class="epp-ar epp-s1">1918-12-22</td>
<td role="cell">Port Bettye</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Marilyne</td>
<td role="cell">Carroll</td>
<td data-value="894067200000" role="cell" class="epp-ar epp-s1">1998-05-02</td>
<td role="cell">Robertsborough</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Mariam</td>
<td role="cell">Kris</td>
<td data-value="1755993600000" role="cell" class="epp-ar epp-s1">2025-08-24</td>
<td role="cell">Edwardhaven</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Savion</td>
<td role="cell">Cartwright</td>
<td data-value="406512000000" role="cell" class="epp-ar epp-s1">1982-11-19</td>
<td role="cell">Veumstad</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Violette</td>
<td role="cell">Pollich</td>
<td data-value="-905299200000" role="cell" class="epp-ar epp-s1">1941-04-25</td>
<td role="cell">Lake Jadynstad</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Percy</td>
<td role="cell">Jacobi</td>
<td data-value="-1333324800000" role="cell" class="epp-ar epp-s1">1927-10-02</td>
<td role="cell">New Reubenmouth</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Wiley</td>
<td role="cell">Kshlerin</td>
<td data-value="-1615334400000" role="cell" class="epp-ar epp-s1">1918-10-25</td>
<td role="cell">Greenholtburgh</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Mitchel</td>
<td role="cell">Powlowski</td>
<td data-value="735696000000" role="cell" class="epp-ar epp-s1">1993-04-25</td>
<td role="cell">Durganland</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Yvette</td>
<td role="cell">Boyle</td>
<td data-value="486000000000" role="cell" class="epp-ar epp-s1">1985-05-27</td>
<td role="cell">North Emmanuelletown</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Fermin</td>
<td role="cell">Lubowitz</td>
<td data-value="795312000000" role="cell" class="epp-ar epp-s1">1995-03-16</td>
<td role="cell">Patiencestad</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Granville</td>
<td role="cell">Lemke</td>
<td data-value="-844992000000" role="cell" class="epp-ar epp-s1">1943-03-24</td>
<td role="cell">East Sigrid</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Emelia</td>
<td role="cell">Cummings</td>
<td data-value="-2060812800000" role="cell" class="epp-ar epp-s1">1904-09-12</td>
<td role="cell">Elyssastad</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Misty</td>
<td role="cell">Wilderman</td>
<td data-value="-156729600000" role="cell" class="epp-ar epp-s1">1965-01-13</td>
<td role="cell">East Rosendo</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Adrian</td>
<td role="cell">Feil</td>
<td data-value="803001600000" role="cell" class="epp-ar epp-s1">1995-06-13</td>
<td role="cell">Weissnatton</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">David</td>
<td role="cell">Schumm</td>
<td data-value="1293148800000" role="cell" class="epp-ar epp-s1">2010-12-24</td>
<td role="cell">North Sydnihaven</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Carol</td>
<td role="cell">Bednar</td>
<td data-value="1115683200000" role="cell" class="epp-ar epp-s1">2005-05-10</td>
<td role="cell">Croninville</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Mia</td>
<td role="cell">Armstrong</td>
<td data-value="-1127174400000" role="cell" class="epp-ar epp-s1">1934-04-14</td>
<td role="cell">Keelingshire</td>
</tr>
</tbody>
</table>
EPPlus converts the table styling in Excel to a separate stylesheet.
table.epplus-table{
font-family:Aptos Narrow;
font-size:11pt;
border-spacing:0;
border-collapse:collapse;
word-wrap:break-word;
white-space:nowrap;
}
.epp-hidden {
display:none;
}
.epp-al {
text-align:left;
}
.epp-ar {
text-align:right;
}
.epp-dcw {
width:64px;
}
.epp-drh {
height:20px;
}
table.epplus-table.ts-dark1 a{
color:#ffffff;
}
table.epplus-table.ts-dark1 td:nth-child(4){
text-align:right;
}
table.epplus-table.ts-dark1{
background-color:#737373;
color:#ffffff;
}
table.epplus-table.ts-dark1 thead{
background-color:#000000;
color:#ffffff;
font-weight:bolder;
border-bottom:medium solid #ffffff;
}
table.epplus-table.ts-dark1 tfoot{
background-color:#262626;
color:#ffffff;
font-weight:bolder;
border-top:medium solid #ffffff;
}
table.epplus-table.ts-dark1-column-stripes tbody tr td:nth-child(odd){
background-color:#404040;
}
table.epplus-table.ts-dark1-row-stripes tbody tr:nth-child(odd){
background-color:#404040;
}
table.epplus-table.ts-dark1-last-column tbody tr td:last-child{
background-color:#404040;
color:#ffffff;
font-weight:bolder;
border-left:medium solid #ffffff;
}
table.epplus-table.ts-dark1-first-column tbody tr td:first-child{
background-color:#404040;
color:#ffffff;
font-weight:bolder;
border-right:medium solid #ffffff;
}
.epp-s1{
white-space: nowrap;
vertical-align:bottom;
}