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">Patrick</td>
<td role="cell">Kunde</td>
<td data-value="-147571200000" role="cell" class="epp-ar">1965-04-29</td>
<td role="cell">Dareton</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Jazmyn</td>
<td role="cell">Braun</td>
<td data-value="1158537600000" role="cell" class="epp-ar">2006-09-18</td>
<td role="cell">Handside</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Vernon</td>
<td role="cell">Littel</td>
<td data-value="1583798400000" role="cell" class="epp-ar">2020-03-10</td>
<td role="cell">Gleichnerville</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Ayana</td>
<td role="cell">Herman</td>
<td data-value="-176688000000" role="cell" class="epp-ar">1964-05-27</td>
<td role="cell">North Deshawn</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Lourdes</td>
<td role="cell">Abernathy</td>
<td data-value="-638496000000" role="cell" class="epp-ar">1949-10-08</td>
<td role="cell">West Ellieview</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Erna</td>
<td role="cell">VonRueden</td>
<td data-value="355104000000" role="cell" class="epp-ar">1981-04-03</td>
<td role="cell">Lake Hillary</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Maida</td>
<td role="cell">Strosin</td>
<td data-value="-108432000000" role="cell" class="epp-ar">1966-07-26</td>
<td role="cell">New Nia</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Lamar</td>
<td role="cell">Hane</td>
<td data-value="-746496000000" role="cell" class="epp-ar">1946-05-07</td>
<td role="cell">South Hiramview</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Justine</td>
<td role="cell">Kling</td>
<td data-value="-1403827200000" role="cell" class="epp-ar">1925-07-08</td>
<td role="cell">Bogisichside</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Lesley</td>
<td role="cell">Heller</td>
<td data-value="-161740800000" role="cell" class="epp-ar">1964-11-16</td>
<td role="cell">Dooleyland</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Ole</td>
<td role="cell">Moen</td>
<td data-value="-19785600000" role="cell" class="epp-ar">1969-05-17</td>
<td role="cell">Hellerstad</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Edyth</td>
<td role="cell">Kautzer</td>
<td data-value="-1920326400000" role="cell" class="epp-ar">1909-02-24</td>
<td role="cell">Petechester</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Reese</td>
<td role="cell">Robel</td>
<td data-value="-800668800000" role="cell" class="epp-ar">1944-08-18</td>
<td role="cell">Zoraton</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Pearlie</td>
<td role="cell">Jacobs</td>
<td data-value="-1638662400000" role="cell" class="epp-ar">1918-01-28</td>
<td role="cell">Dietrichstad</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Rickey</td>
<td role="cell">Haag</td>
<td data-value="-413856000000" role="cell" class="epp-ar">1956-11-20</td>
<td role="cell">New Wilfrid</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Bertrand</td>
<td role="cell">Strosin</td>
<td data-value="1381795200000" role="cell" class="epp-ar">2013-10-15</td>
<td role="cell">Schimmelborough</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Gennaro</td>
<td role="cell">Stamm</td>
<td data-value="1080864000000" role="cell" class="epp-ar">2004-04-02</td>
<td role="cell">Fritschview</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Ardella</td>
<td role="cell">Kassulke</td>
<td data-value="-139017600000" role="cell" class="epp-ar">1965-08-06</td>
<td role="cell">New Agustinchester</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Hillary</td>
<td role="cell">Zulauf</td>
<td data-value="-294710400000" role="cell" class="epp-ar">1960-08-30</td>
<td role="cell">North Harmon</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Jaunita</td>
<td role="cell">Padberg</td>
<td data-value="1126915200000" role="cell" class="epp-ar">2005-09-17</td>
<td role="cell">North Geovanyview</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Jerome</td>
<td role="cell">Kling</td>
<td data-value="-139622400000" role="cell" class="epp-ar">1965-07-30</td>
<td role="cell">Lebsackville</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Bailey</td>
<td role="cell">Gerhold</td>
<td data-value="-602553600000" role="cell" class="epp-ar">1950-11-28</td>
<td role="cell">West Scottietown</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Marcelo</td>
<td role="cell">Parker</td>
<td data-value="1126483200000" role="cell" class="epp-ar">2005-09-12</td>
<td role="cell">Joelleville</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Cynthia</td>
<td role="cell">Gleichner</td>
<td data-value="-1106956800000" role="cell" class="epp-ar">1934-12-04</td>
<td role="cell">New Aryanna</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Beryl</td>
<td role="cell">Armstrong</td>
<td data-value="1146787200000" role="cell" class="epp-ar">2006-05-05</td>
<td role="cell">Bergstromport</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Gia</td>
<td role="cell">Bauch</td>
<td data-value="-155865600000" role="cell" class="epp-ar">1965-01-23</td>
<td role="cell">Grantshire</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Mayra</td>
<td role="cell">Kassulke</td>
<td data-value="-613526400000" role="cell" class="epp-ar">1950-07-24</td>
<td role="cell">East Raymond</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Krista</td>
<td role="cell">Williamson</td>
<td data-value="-290995200000" role="cell" class="epp-ar">1960-10-12</td>
<td role="cell">Jackelinefurt</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Maurine</td>
<td role="cell">Ledner</td>
<td data-value="1593907200000" role="cell" class="epp-ar">2020-07-05</td>
<td role="cell">South Omerborough</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Sid</td>
<td role="cell">Nitzsche</td>
<td data-value="-820540800000" role="cell" class="epp-ar">1944-01-01</td>
<td role="cell">North Chanelle</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Weston</td>
<td role="cell">Parisian</td>
<td data-value="167443200000" role="cell" class="epp-ar">1975-04-23</td>
<td role="cell">West Leland</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Flavie</td>
<td role="cell">Walsh</td>
<td data-value="-461808000000" role="cell" class="epp-ar">1955-05-15</td>
<td role="cell">East Kyleview</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Kelly</td>
<td role="cell">Bailey</td>
<td data-value="226108800000" role="cell" class="epp-ar">1977-03-02</td>
<td role="cell">Violahaven</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Tamara</td>
<td role="cell">Spinka</td>
<td data-value="721008000000" role="cell" class="epp-ar">1992-11-06</td>
<td role="cell">Bradtkefurt</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Ari</td>
<td role="cell">O'Conner</td>
<td data-value="-2066169600000" role="cell" class="epp-ar">1904-07-12</td>
<td role="cell">East Wava</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Kelley</td>
<td role="cell">Rempel</td>
<td data-value="-644630400000" role="cell" class="epp-ar">1949-07-29</td>
<td role="cell">Randalchester</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Della</td>
<td role="cell">Brekke</td>
<td data-value="-1284508800000" role="cell" class="epp-ar">1929-04-19</td>
<td role="cell">Lake Harley</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Kirsten</td>
<td role="cell">Willms</td>
<td data-value="-1121644800000" role="cell" class="epp-ar">1934-06-17</td>
<td role="cell">Sofiaport</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Richard</td>
<td role="cell">Kreiger</td>
<td data-value="-1620345600000" role="cell" class="epp-ar">1918-08-28</td>
<td role="cell">North Caseyhaven</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Chelsea</td>
<td role="cell">Bergnaum</td>
<td data-value="175305600000" role="cell" class="epp-ar">1975-07-23</td>
<td role="cell">West Kennithville</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Sherman</td>
<td role="cell">Langworth</td>
<td data-value="-165369600000" role="cell" class="epp-ar">1964-10-05</td>
<td role="cell">North Dolly</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Cristopher</td>
<td role="cell">Fay</td>
<td data-value="-155347200000" role="cell" class="epp-ar">1965-01-29</td>
<td role="cell">Lawrenceland</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Vincent</td>
<td role="cell">Mraz</td>
<td data-value="-143251200000" role="cell" class="epp-ar">1965-06-18</td>
<td role="cell">Nolanchester</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Finn</td>
<td role="cell">Oberbrunner</td>
<td data-value="1247270400000" role="cell" class="epp-ar">2009-07-11</td>
<td role="cell">Lambertberg</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Everett</td>
<td role="cell">Lueilwitz</td>
<td data-value="62812800000" role="cell" class="epp-ar">1971-12-29</td>
<td role="cell">Odafort</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Emil</td>
<td role="cell">Kovacek</td>
<td data-value="-711072000000" role="cell" class="epp-ar">1947-06-21</td>
<td role="cell">New Queen</td>
</tr>
<tr role="row" scope="row">
<td role="cell">England</td>
<td role="cell">Vladimir</td>
<td role="cell">Volkman</td>
<td data-value="-151804800000" role="cell" class="epp-ar">1965-03-11</td>
<td role="cell">Port Ashlyfort</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Scotland</td>
<td role="cell">Colby</td>
<td role="cell">Feest</td>
<td data-value="-1038182400000" role="cell" class="epp-ar">1937-02-07</td>
<td role="cell">Gradyfort</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Northern Ireland</td>
<td role="cell">Daisy</td>
<td role="cell">Koss</td>
<td data-value="-1520812800000" role="cell" class="epp-ar">1921-10-23</td>
<td role="cell">Crookschester</td>
</tr>
<tr role="row" scope="row">
<td role="cell">Wales</td>
<td role="cell">Kamron</td>
<td role="cell">Ankunding</td>
<td data-value="711331200000" role="cell" class="epp-ar">1992-07-17</td>
<td role="cell">Port Jovannyport</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;
}