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">England</td>
<td role="cell">Erna</td>
<td role="cell">Dickinson</td>
<td data-value="1243987200000" role="cell" class="epp-ar">2009-06-03</td>
<td role="cell">Jonesside</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Gloria</td>
<td role="cell">Hudson</td>
<td data-value="-1350345600000" role="cell" class="epp-ar">1927-03-19</td>
<td role="cell">Kirlinshire</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Magali</td>
<td role="cell">Balistreri</td>
<td data-value="345427200000" role="cell" class="epp-ar">1980-12-12</td>
<td role="cell">North Sydniview</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Wilfrid</td>
<td role="cell">Gutmann</td>
<td data-value="-1217116800000" role="cell" class="epp-ar">1931-06-08</td>
<td role="cell">Kundeshire</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Ethyl</td>
<td role="cell">Kshlerin</td>
<td data-value="-919987200000" role="cell" class="epp-ar">1940-11-06</td>
<td role="cell">Amparoport</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Isobel</td>
<td role="cell">Runte</td>
<td data-value="197596800000" role="cell" class="epp-ar">1976-04-06</td>
<td role="cell">Burniceland</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Yvonne</td>
<td role="cell">Bashirian</td>
<td data-value="-942105600000" role="cell" class="epp-ar">1940-02-24</td>
<td role="cell">West Claudineview</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Emmalee</td>
<td role="cell">Renner</td>
<td data-value="996624000000" role="cell" class="epp-ar">2001-08-01</td>
<td role="cell">Koeppburgh</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Ethan</td>
<td role="cell">Shields</td>
<td data-value="397353600000" role="cell" class="epp-ar">1982-08-05</td>
<td role="cell">Port Kaci</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Letitia</td>
<td role="cell">Berge</td>
<td data-value="962841600000" role="cell" class="epp-ar">2000-07-06</td>
<td role="cell">East Josie</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Mable</td>
<td role="cell">Cassin</td>
<td data-value="-1533427200000" role="cell" class="epp-ar">1921-05-30</td>
<td role="cell">North Estellmouth</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Raquel</td>
<td role="cell">Yost</td>
<td data-value="-538444800000" role="cell" class="epp-ar">1952-12-09</td>
<td role="cell">Jennieside</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Hanna</td>
<td role="cell">Ernser</td>
<td data-value="-359769600000" role="cell" class="epp-ar">1958-08-08</td>
<td role="cell">North Lavinaburgh</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Cassandre</td>
<td role="cell">Davis</td>
<td data-value="-1123200000" role="cell" class="epp-ar">1969-12-19</td>
<td role="cell">North Jalon</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Ahmed</td>
<td role="cell">Schuppe</td>
<td data-value="-358041600000" role="cell" class="epp-ar">1958-08-28</td>
<td role="cell">New Pinkchester</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Itzel</td>
<td role="cell">Nicolas</td>
<td data-value="-1243814400000" role="cell" class="epp-ar">1930-08-03</td>
<td role="cell">Lake Bo</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Desmond</td>
<td role="cell">Cruickshank</td>
<td data-value="451094400000" role="cell" class="epp-ar">1984-04-18</td>
<td role="cell">North Edison</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Erwin</td>
<td role="cell">Kohler</td>
<td data-value="210211200000" role="cell" class="epp-ar">1976-08-30</td>
<td role="cell">East Idellside</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Caden</td>
<td role="cell">Herzog</td>
<td data-value="-11145600000" role="cell" class="epp-ar">1969-08-25</td>
<td role="cell">East Jana</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Gunner</td>
<td role="cell">Price</td>
<td data-value="-196300800000" role="cell" class="epp-ar">1963-10-13</td>
<td role="cell">East Tabithamouth</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Brook</td>
<td role="cell">Blick</td>
<td data-value="346464000000" role="cell" class="epp-ar">1980-12-24</td>
<td role="cell">Port Joshuamouth</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Joe</td>
<td role="cell">Nicolas</td>
<td data-value="-2100643200000" role="cell" class="epp-ar">1903-06-09</td>
<td role="cell">Auerborough</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Margret</td>
<td role="cell">Yost</td>
<td data-value="-836438400000" role="cell" class="epp-ar">1943-07-01</td>
<td role="cell">Watersmouth</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Vella</td>
<td role="cell">Leffler</td>
<td data-value="-159840000000" role="cell" class="epp-ar">1964-12-08</td>
<td role="cell">Fredville</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Dianna</td>
<td role="cell">Rogahn</td>
<td data-value="-1806969600000" role="cell" class="epp-ar">1912-09-28</td>
<td role="cell">New Alphonso</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Abby</td>
<td role="cell">Tremblay</td>
<td data-value="205459200000" role="cell" class="epp-ar">1976-07-06</td>
<td role="cell">Port Alvah</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Abdiel</td>
<td role="cell">Beahan</td>
<td data-value="-294710400000" role="cell" class="epp-ar">1960-08-30</td>
<td role="cell">Lake Sierraside</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Zena</td>
<td role="cell">McCullough</td>
<td data-value="-1539388800000" role="cell" class="epp-ar">1921-03-22</td>
<td role="cell">East Dawson</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Reed</td>
<td role="cell">Boyle</td>
<td data-value="-160617600000" role="cell" class="epp-ar">1964-11-29</td>
<td role="cell">West Gail</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Ally</td>
<td role="cell">Shields</td>
<td data-value="-1551657600000" role="cell" class="epp-ar">1920-10-31</td>
<td role="cell">South Tremaynemouth</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Bettie</td>
<td role="cell">Wolff</td>
<td data-value="-1596931200000" role="cell" class="epp-ar">1919-05-26</td>
<td role="cell">Schmittmouth</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Keegan</td>
<td role="cell">Glover</td>
<td data-value="-162518400000" role="cell" class="epp-ar">1964-11-07</td>
<td role="cell">North Favianmouth</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Jaren</td>
<td role="cell">Koch</td>
<td data-value="720489600000" role="cell" class="epp-ar">1992-10-31</td>
<td role="cell">Mittieport</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Enola</td>
<td role="cell">Runte</td>
<td data-value="669600000000" role="cell" class="epp-ar">1991-03-22</td>
<td role="cell">Konopelskishire</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Darrin</td>
<td role="cell">Wolff</td>
<td data-value="-169430400000" role="cell" class="epp-ar">1964-08-19</td>
<td role="cell">Langworthton</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Julian</td>
<td role="cell">Prosacco</td>
<td data-value="-491875200000" role="cell" class="epp-ar">1954-06-01</td>
<td role="cell">Haneburgh</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Meghan</td>
<td role="cell">Kertzmann</td>
<td data-value="-236390400000" role="cell" class="epp-ar">1962-07-06</td>
<td role="cell">Jordistad</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Rosanna</td>
<td role="cell">Kilback</td>
<td data-value="-1222387200000" role="cell" class="epp-ar">1931-04-08</td>
<td role="cell">South Kennedichester</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Cara</td>
<td role="cell">Fritsch</td>
<td data-value="463449600000" role="cell" class="epp-ar">1984-09-08</td>
<td role="cell">South Humbertoborough</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Lottie</td>
<td role="cell">Bergstrom</td>
<td data-value="-175737600000" role="cell" class="epp-ar">1964-06-07</td>
<td role="cell">Port Alanisland</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Brenden</td>
<td role="cell">Effertz</td>
<td data-value="1026777600000" role="cell" class="epp-ar">2002-07-16</td>
<td role="cell">East Matildemouth</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Jennyfer</td>
<td role="cell">Vandervort</td>
<td data-value="442195200000" role="cell" class="epp-ar">1984-01-06</td>
<td role="cell">North Bridgetteborough</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Viola</td>
<td role="cell">McClure</td>
<td data-value="-821664000000" role="cell" class="epp-ar">1943-12-19</td>
<td role="cell">Coleton</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Cindy</td>
<td role="cell">Herzog</td>
<td data-value="-1299283200000" role="cell" class="epp-ar">1928-10-30</td>
<td role="cell">Gloverhaven</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Krystina</td>
<td role="cell">Metz</td>
<td data-value="-168566400000" role="cell" class="epp-ar">1964-08-29</td>
<td role="cell">Lake Verda</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Erich</td>
<td role="cell">Hettinger</td>
<td data-value="-948672000000" role="cell" class="epp-ar">1939-12-10</td>
<td role="cell">South Herminia</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Dora</td>
<td role="cell">Herzog</td>
<td data-value="-213148800000" role="cell" class="epp-ar">1963-04-01</td>
<td role="cell">Finnton</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Jordyn</td>
<td role="cell">Harris</td>
<td data-value="842659200000" role="cell" class="epp-ar">1996-09-14</td>
<td role="cell">Strackehaven</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Jimmie</td>
<td role="cell">Kirlin</td>
<td data-value="229046400000" role="cell" class="epp-ar">1977-04-05</td>
<td role="cell">South Forrest</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Agustin</td>
<td role="cell">D'Amore</td>
<td data-value="763430400000" role="cell" class="epp-ar">1994-03-12</td>
<td role="cell">Ramonaside</td>
</tr>
</tbody>
</table>
EPPlus converts the table styling in Excel to a separate stylesheet.
table.epplus-table{
font-family:Calibri;
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;
}