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.

The checkboxes below demonstrates that you can use the html/css from EPPlus with css/javascript from other frameworks

Country FirstName LastName BirthDate City
Northern Ireland Emmalee Little 1965-04-25 McClureland
Northern Ireland Arjun King 1907-10-22 Lake Felipaburgh
Scotland Leonor Koss 2014-09-30 Alanamouth
England Jorge Hodkiewicz 1962-01-12 Port Cedrick
Scotland Jairo Reichel 1925-03-01 Mertzborough
England Nico Koss 1964-12-24 Runolfsdottirview
England Eugene Krajcik 2010-05-08 Port Nakiahaven
Wales Helmer Reichel 1930-04-15 Hunterside
Scotland Zakary Langosh 1969-01-30 Port Stuart
Wales Raven Gleichner 1959-02-09 Port Carolyne
Wales Ewald Steuber 1965-10-16 North Ramiro
England Justus Collier 1956-06-28 Lake Brennonstad
Wales Joanie McGlynn 2023-08-09 Port Letitia
Scotland Joany McLaughlin 1944-06-19 West Luna
Wales Olga Mills 2008-10-28 Effertztown
Northern Ireland Christiana Schmidt 1958-10-15 North Russelfurt
Northern Ireland Caroline Gusikowski 2005-01-01 New Deontae
Wales Uriah Rath 1950-05-23 Port Eudora
Scotland Kenna Morar 1980-05-20 East Eunice
England Everardo Reichert 1965-06-14 West Abrahamview
England Marco Rowe 1964-07-31 Langoshbury
Wales Alec Hand 1962-03-04 Lake Dandre
Wales Morgan Hahn 1974-02-10 East Jennyferfort
Scotland Meda Breitenberg 2021-12-08 East Trishaland
Northern Ireland Janet Turner 2013-05-15 North Vernice
England Edna Mueller 2026-06-22 Cecilefurt
Northern Ireland Buford Emmerich 2013-10-19 Lake Billy
Scotland Major Wiegand 1987-09-06 East Rossie
Wales Kelley Emmerich 1923-04-29 Lake Ona
England Madie Nitzsche 1964-11-14 East Zane
Northern Ireland Isabelle Dibbert 2017-10-03 West Hester
Northern Ireland Quentin Gleason 1999-03-04 Bettieborough
England Susanna Kiehn 1964-12-23 New Imanishire
Wales Imani Runolfsdottir 1936-04-04 Vidalmouth
Scotland Mateo Murray 1992-07-31 New Saraitown
England Jaylan Kertzmann 1947-05-02 Yundttown
Scotland Marina Watsica 1947-11-08 Kesslerside
Scotland Samson Gutkowski 2003-03-23 Denesiktown
England Murray Leuschke 2012-02-18 Davisland
Scotland Delta Okuneva 2013-03-01 Port Elyssa
Scotland Jeanette Gulgowski 1976-05-07 Lemkechester
Wales Ewald Schaden 1986-11-23 Parisiantown
Wales Noel Gaylord 2022-04-09 Nilsborough
England Alisha Hagenes 1976-07-17 Gaylordshire
Scotland Belle Lind 2014-06-14 North Jeramy
Northern Ireland Mavis McGlynn 1965-08-17 Krystalshire
Northern Ireland Winfield Marks 1949-12-31 Lake Dorothea
Scotland Shyann Howe 1922-02-02 Reynoldshaven
England Devonte Eichmann 1955-03-29 West Petechester
Scotland Linwood Veum 1977-05-02 Albinaville

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">Emmalee</td>
      <td role="cell">Little</td>
      <td data-value="-147916800000" role="cell" class="epp-ar epp-s1">1965-04-25</td>
      <td role="cell">McClureland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Arjun</td>
      <td role="cell">King</td>
      <td data-value="-1962748800000" role="cell" class="epp-ar epp-s1">1907-10-22</td>
      <td role="cell">Lake Felipaburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Leonor</td>
      <td role="cell">Koss</td>
      <td data-value="1412035200000" role="cell" class="epp-ar epp-s1">2014-09-30</td>
      <td role="cell">Alanamouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Jorge</td>
      <td role="cell">Hodkiewicz</td>
      <td data-value="-251510400000" role="cell" class="epp-ar epp-s1">1962-01-12</td>
      <td role="cell">Port Cedrick</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jairo</td>
      <td role="cell">Reichel</td>
      <td data-value="-1414972800000" role="cell" class="epp-ar epp-s1">1925-03-01</td>
      <td role="cell">Mertzborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Nico</td>
      <td role="cell">Koss</td>
      <td data-value="-158457600000" role="cell" class="epp-ar epp-s1">1964-12-24</td>
      <td role="cell">Runolfsdottirview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Eugene</td>
      <td role="cell">Krajcik</td>
      <td data-value="1273276800000" role="cell" class="epp-ar epp-s1">2010-05-08</td>
      <td role="cell">Port Nakiahaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Helmer</td>
      <td role="cell">Reichel</td>
      <td data-value="-1253318400000" role="cell" class="epp-ar epp-s1">1930-04-15</td>
      <td role="cell">Hunterside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Zakary</td>
      <td role="cell">Langosh</td>
      <td data-value="-29030400000" role="cell" class="epp-ar epp-s1">1969-01-30</td>
      <td role="cell">Port Stuart</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Raven</td>
      <td role="cell">Gleichner</td>
      <td data-value="-343785600000" role="cell" class="epp-ar epp-s1">1959-02-09</td>
      <td role="cell">Port Carolyne</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Ewald</td>
      <td role="cell">Steuber</td>
      <td data-value="-132883200000" role="cell" class="epp-ar epp-s1">1965-10-16</td>
      <td role="cell">North Ramiro</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Justus</td>
      <td role="cell">Collier</td>
      <td data-value="-426384000000" role="cell" class="epp-ar epp-s1">1956-06-28</td>
      <td role="cell">Lake Brennonstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Joanie</td>
      <td role="cell">McGlynn</td>
      <td data-value="1691539200000" role="cell" class="epp-ar epp-s1">2023-08-09</td>
      <td role="cell">Port Letitia</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Joany</td>
      <td role="cell">McLaughlin</td>
      <td data-value="-805852800000" role="cell" class="epp-ar epp-s1">1944-06-19</td>
      <td role="cell">West Luna</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Olga</td>
      <td role="cell">Mills</td>
      <td data-value="1225152000000" role="cell" class="epp-ar epp-s1">2008-10-28</td>
      <td role="cell">Effertztown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Christiana</td>
      <td role="cell">Schmidt</td>
      <td data-value="-353894400000" role="cell" class="epp-ar epp-s1">1958-10-15</td>
      <td role="cell">North Russelfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Caroline</td>
      <td role="cell">Gusikowski</td>
      <td data-value="1104537600000" role="cell" class="epp-ar epp-s1">2005-01-01</td>
      <td role="cell">New Deontae</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Uriah</td>
      <td role="cell">Rath</td>
      <td data-value="-618883200000" role="cell" class="epp-ar epp-s1">1950-05-23</td>
      <td role="cell">Port Eudora</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Kenna</td>
      <td role="cell">Morar</td>
      <td data-value="327628800000" role="cell" class="epp-ar epp-s1">1980-05-20</td>
      <td role="cell">East Eunice</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Everardo</td>
      <td role="cell">Reichert</td>
      <td data-value="-143596800000" role="cell" class="epp-ar epp-s1">1965-06-14</td>
      <td role="cell">West Abrahamview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Marco</td>
      <td role="cell">Rowe</td>
      <td data-value="-171072000000" role="cell" class="epp-ar epp-s1">1964-07-31</td>
      <td role="cell">Langoshbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Alec</td>
      <td role="cell">Hand</td>
      <td data-value="-247104000000" role="cell" class="epp-ar epp-s1">1962-03-04</td>
      <td role="cell">Lake Dandre</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Morgan</td>
      <td role="cell">Hahn</td>
      <td data-value="129686400000" role="cell" class="epp-ar epp-s1">1974-02-10</td>
      <td role="cell">East Jennyferfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Meda</td>
      <td role="cell">Breitenberg</td>
      <td data-value="1638921600000" role="cell" class="epp-ar epp-s1">2021-12-08</td>
      <td role="cell">East Trishaland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Janet</td>
      <td role="cell">Turner</td>
      <td data-value="1368576000000" role="cell" class="epp-ar epp-s1">2013-05-15</td>
      <td role="cell">North Vernice</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Edna</td>
      <td role="cell">Mueller</td>
      <td data-value="1782086400000" role="cell" class="epp-ar epp-s1">2026-06-22</td>
      <td role="cell">Cecilefurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Buford</td>
      <td role="cell">Emmerich</td>
      <td data-value="1382140800000" role="cell" class="epp-ar epp-s1">2013-10-19</td>
      <td role="cell">Lake Billy</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Major</td>
      <td role="cell">Wiegand</td>
      <td data-value="557884800000" role="cell" class="epp-ar epp-s1">1987-09-06</td>
      <td role="cell">East Rossie</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Kelley</td>
      <td role="cell">Emmerich</td>
      <td data-value="-1473033600000" role="cell" class="epp-ar epp-s1">1923-04-29</td>
      <td role="cell">Lake Ona</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Madie</td>
      <td role="cell">Nitzsche</td>
      <td data-value="-161913600000" role="cell" class="epp-ar epp-s1">1964-11-14</td>
      <td role="cell">East Zane</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Isabelle</td>
      <td role="cell">Dibbert</td>
      <td data-value="1506988800000" role="cell" class="epp-ar epp-s1">2017-10-03</td>
      <td role="cell">West Hester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Quentin</td>
      <td role="cell">Gleason</td>
      <td data-value="920505600000" role="cell" class="epp-ar epp-s1">1999-03-04</td>
      <td role="cell">Bettieborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Susanna</td>
      <td role="cell">Kiehn</td>
      <td data-value="-158544000000" role="cell" class="epp-ar epp-s1">1964-12-23</td>
      <td role="cell">New Imanishire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Imani</td>
      <td role="cell">Runolfsdottir</td>
      <td data-value="-1064880000000" role="cell" class="epp-ar epp-s1">1936-04-04</td>
      <td role="cell">Vidalmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Mateo</td>
      <td role="cell">Murray</td>
      <td data-value="712540800000" role="cell" class="epp-ar epp-s1">1992-07-31</td>
      <td role="cell">New Saraitown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Jaylan</td>
      <td role="cell">Kertzmann</td>
      <td data-value="-715392000000" role="cell" class="epp-ar epp-s1">1947-05-02</td>
      <td role="cell">Yundttown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Marina</td>
      <td role="cell">Watsica</td>
      <td data-value="-698976000000" role="cell" class="epp-ar epp-s1">1947-11-08</td>
      <td role="cell">Kesslerside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Samson</td>
      <td role="cell">Gutkowski</td>
      <td data-value="1048377600000" role="cell" class="epp-ar epp-s1">2003-03-23</td>
      <td role="cell">Denesiktown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Murray</td>
      <td role="cell">Leuschke</td>
      <td data-value="1329523200000" role="cell" class="epp-ar epp-s1">2012-02-18</td>
      <td role="cell">Davisland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Delta</td>
      <td role="cell">Okuneva</td>
      <td data-value="1362096000000" role="cell" class="epp-ar epp-s1">2013-03-01</td>
      <td role="cell">Port Elyssa</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jeanette</td>
      <td role="cell">Gulgowski</td>
      <td data-value="200275200000" role="cell" class="epp-ar epp-s1">1976-05-07</td>
      <td role="cell">Lemkechester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Ewald</td>
      <td role="cell">Schaden</td>
      <td data-value="533088000000" role="cell" class="epp-ar epp-s1">1986-11-23</td>
      <td role="cell">Parisiantown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Noel</td>
      <td role="cell">Gaylord</td>
      <td data-value="1649462400000" role="cell" class="epp-ar epp-s1">2022-04-09</td>
      <td role="cell">Nilsborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Alisha</td>
      <td role="cell">Hagenes</td>
      <td data-value="206409600000" role="cell" class="epp-ar epp-s1">1976-07-17</td>
      <td role="cell">Gaylordshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Belle</td>
      <td role="cell">Lind</td>
      <td data-value="1402704000000" role="cell" class="epp-ar epp-s1">2014-06-14</td>
      <td role="cell">North Jeramy</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Mavis</td>
      <td role="cell">McGlynn</td>
      <td data-value="-138067200000" role="cell" class="epp-ar epp-s1">1965-08-17</td>
      <td role="cell">Krystalshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Winfield</td>
      <td role="cell">Marks</td>
      <td data-value="-631238400000" role="cell" class="epp-ar epp-s1">1949-12-31</td>
      <td role="cell">Lake Dorothea</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Shyann</td>
      <td role="cell">Howe</td>
      <td data-value="-1512000000000" role="cell" class="epp-ar epp-s1">1922-02-02</td>
      <td role="cell">Reynoldshaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Devonte</td>
      <td role="cell">Eichmann</td>
      <td data-value="-465868800000" role="cell" class="epp-ar epp-s1">1955-03-29</td>
      <td role="cell">West Petechester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Linwood</td>
      <td role="cell">Veum</td>
      <td data-value="231379200000" role="cell" class="epp-ar epp-s1">1977-05-02</td>
      <td role="cell">Albinaville</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;
}