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">Wales</td>
<td role="cell">Zoey</td>
<td role="cell">Casper</td>
<td data-value="-2082758400000" role="cell" class="epp-ar">1904-01-02</td>
<td role="cell">Fannybury</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Rosalind</td>
<td role="cell">O'Reilly</td>
<td data-value="-718675200000" role="cell" class="epp-ar">1947-03-25</td>
<td role="cell">Stanshire</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Odell</td>
<td role="cell">Kling</td>
<td data-value="-1475020800000" role="cell" class="epp-ar">1923-04-06</td>
<td role="cell">Londontown</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Richie</td>
<td role="cell">Breitenberg</td>
<td data-value="424483200000" role="cell" class="epp-ar">1983-06-15</td>
<td role="cell">Lake Eltonburgh</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Michale</td>
<td role="cell">Stark</td>
<td data-value="-489110400000" role="cell" class="epp-ar">1954-07-03</td>
<td role="cell">South Otisborough</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Alana</td>
<td role="cell">Johns</td>
<td data-value="1242259200000" role="cell" class="epp-ar">2009-05-14</td>
<td role="cell">Boscoview</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Eriberto</td>
<td role="cell">Nicolas</td>
<td data-value="727228800000" role="cell" class="epp-ar">1993-01-17</td>
<td role="cell">West Christianaberg</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Etha</td>
<td role="cell">Gusikowski</td>
<td data-value="1140825600000" role="cell" class="epp-ar">2006-02-25</td>
<td role="cell">South Brennaberg</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Landen</td>
<td role="cell">Reinger</td>
<td data-value="-1078617600000" role="cell" class="epp-ar">1935-10-28</td>
<td role="cell">South Willaton</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Jessie</td>
<td role="cell">Stehr</td>
<td data-value="-1514160000000" role="cell" class="epp-ar">1922-01-08</td>
<td role="cell">North Jaylon</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Abdullah</td>
<td role="cell">Kunde</td>
<td data-value="772848000000" role="cell" class="epp-ar">1994-06-29</td>
<td role="cell">Kleinburgh</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Gloria</td>
<td role="cell">Reichel</td>
<td data-value="-161740800000" role="cell" class="epp-ar">1964-11-16</td>
<td role="cell">East Mara</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Velda</td>
<td role="cell">Bednar</td>
<td data-value="1459382400000" role="cell" class="epp-ar">2016-03-31</td>
<td role="cell">Beulahport</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Dariana</td>
<td role="cell">Collier</td>
<td data-value="296179200000" role="cell" class="epp-ar">1979-05-22</td>
<td role="cell">East Axelbury</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Piper</td>
<td role="cell">Lind</td>
<td data-value="525312000000" role="cell" class="epp-ar">1986-08-25</td>
<td role="cell">North Casimirview</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Evert</td>
<td role="cell">Wolff</td>
<td data-value="-1214006400000" role="cell" class="epp-ar">1931-07-14</td>
<td role="cell">Hauckchester</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Sydni</td>
<td role="cell">Larkin</td>
<td data-value="-2079734400000" role="cell" class="epp-ar">1904-02-06</td>
<td role="cell">Jacobiland</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Mariano</td>
<td role="cell">Hayes</td>
<td data-value="-158457600000" role="cell" class="epp-ar">1964-12-24</td>
<td role="cell">Dewitthaven</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Laverne</td>
<td role="cell">Beer</td>
<td data-value="-928800000000" role="cell" class="epp-ar">1940-07-27</td>
<td role="cell">Port Margarita</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Bernie</td>
<td role="cell">Nader</td>
<td data-value="-157334400000" role="cell" class="epp-ar">1965-01-06</td>
<td role="cell">Port Olaf</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Zetta</td>
<td role="cell">Mertz</td>
<td data-value="1708300800000" role="cell" class="epp-ar">2024-02-19</td>
<td role="cell">Roderickfort</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Marjolaine</td>
<td role="cell">Witting</td>
<td data-value="-1607644800000" role="cell" class="epp-ar">1919-01-22</td>
<td role="cell">South Arianna</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Maribel</td>
<td role="cell">Adams</td>
<td data-value="-565574400000" role="cell" class="epp-ar">1952-01-30</td>
<td role="cell">Huntertown</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Lacy</td>
<td role="cell">Stehr</td>
<td data-value="-1103068800000" role="cell" class="epp-ar">1935-01-18</td>
<td role="cell">Grahamfort</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Monica</td>
<td role="cell">Kihn</td>
<td data-value="-805075200000" role="cell" class="epp-ar">1944-06-28</td>
<td role="cell">Dahliatown</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Beulah</td>
<td role="cell">Hilll</td>
<td data-value="-170294400000" role="cell" class="epp-ar">1964-08-09</td>
<td role="cell">Lake Kayla</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Isai</td>
<td role="cell">Johnson</td>
<td data-value="81993600000" role="cell" class="epp-ar">1972-08-07</td>
<td role="cell">Cleoton</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Luz</td>
<td role="cell">Schiller</td>
<td data-value="-1420848000000" role="cell" class="epp-ar">1924-12-23</td>
<td role="cell">South Melisaton</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Malika</td>
<td role="cell">O'Kon</td>
<td data-value="60480000000" role="cell" class="epp-ar">1971-12-02</td>
<td role="cell">Isommouth</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Alphonso</td>
<td role="cell">Hilpert</td>
<td data-value="-168220800000" role="cell" class="epp-ar">1964-09-02</td>
<td role="cell">Emmanuelmouth</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Oleta</td>
<td role="cell">Ankunding</td>
<td data-value="-1442620800000" role="cell" class="epp-ar">1924-04-15</td>
<td role="cell">McClureborough</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Marianne</td>
<td role="cell">Satterfield</td>
<td data-value="1023062400000" role="cell" class="epp-ar">2002-06-03</td>
<td role="cell">Port Karina</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Maurice</td>
<td role="cell">Nicolas</td>
<td data-value="-169171200000" role="cell" class="epp-ar">1964-08-22</td>
<td role="cell">Diamondburgh</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Gaylord</td>
<td role="cell">Will</td>
<td data-value="-141696000000" role="cell" class="epp-ar">1965-07-06</td>
<td role="cell">Dietrichburgh</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Hollie</td>
<td role="cell">Hauck</td>
<td data-value="282960000000" role="cell" class="epp-ar">1978-12-20</td>
<td role="cell">Lake Moniqueton</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Filomena</td>
<td role="cell">Ratke</td>
<td data-value="-1445731200000" role="cell" class="epp-ar">1924-03-10</td>
<td role="cell">Fletabury</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Henry</td>
<td role="cell">Hettinger</td>
<td data-value="-635990400000" role="cell" class="epp-ar">1949-11-06</td>
<td role="cell">O'Haraberg</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Bill</td>
<td role="cell">Hegmann</td>
<td data-value="-1213833600000" role="cell" class="epp-ar">1931-07-16</td>
<td role="cell">Beckerport</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Pauline</td>
<td role="cell">Greenholt</td>
<td data-value="-430185600000" role="cell" class="epp-ar">1956-05-15</td>
<td role="cell">Lake Delpha</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Jackeline</td>
<td role="cell">Eichmann</td>
<td data-value="1240617600000" role="cell" class="epp-ar">2009-04-25</td>
<td role="cell">South Birdieberg</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Elenora</td>
<td role="cell">Dicki</td>
<td data-value="2592000000" role="cell" class="epp-ar">1970-01-31</td>
<td role="cell">Strackeborough</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Virginie</td>
<td role="cell">McLaughlin</td>
<td data-value="-364435200000" role="cell" class="epp-ar">1958-06-15</td>
<td role="cell">Port Marcelle</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Malika</td>
<td role="cell">Hilpert</td>
<td data-value="242697600000" role="cell" class="epp-ar">1977-09-10</td>
<td role="cell">Lake Ruthie</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Elizabeth</td>
<td role="cell">Lueilwitz</td>
<td data-value="334713600000" role="cell" class="epp-ar">1980-08-10</td>
<td role="cell">Port Theoton</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Simeon</td>
<td role="cell">Pfeffer</td>
<td data-value="1771459200000" role="cell" class="epp-ar">2026-02-19</td>
<td role="cell">Botsfordton</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Talon</td>
<td role="cell">Ratke</td>
<td data-value="-1043280000000" role="cell" class="epp-ar">1936-12-10</td>
<td role="cell">New Geotown</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Susan</td>
<td role="cell">Huels</td>
<td data-value="-1152230400000" role="cell" class="epp-ar">1933-06-28</td>
<td role="cell">South Lemueltown</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Christian</td>
<td role="cell">Collins</td>
<td data-value="-1409529600000" role="cell" class="epp-ar">1925-05-03</td>
<td role="cell">West Kimberlyport</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Colton</td>
<td role="cell">Jast</td>
<td data-value="1195344000000" role="cell" class="epp-ar">2007-11-18</td>
<td role="cell">Hillarymouth</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Lysanne</td>
<td role="cell">Mills</td>
<td data-value="-27302400000" role="cell" class="epp-ar">1969-02-19</td>
<td role="cell">Melanyborough</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;
}