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
Scotland Chelsea Ortiz 1911-08-19 North Shaun
Northern Ireland Garrett Conn 1917-07-31 Lake Elwynmouth
England Rusty Bode 2008-12-02 New Joshua
England Kathlyn Kris 1964-09-05 New Paige
Northern Ireland Carolyne Feil 1989-02-06 Koelpinstad
Wales Jaquelin Jacobson 1913-04-26 Kuhnfurt
Northern Ireland Jorge Terry 2019-05-01 Jarenland
Wales Judge Dach 1946-07-18 Nicoleberg
England Freddy Batz 2008-04-25 Douglasmouth
Northern Ireland Ben Pacocha 1960-02-09 Lake Ana
Scotland Jerrod Parker 2006-05-22 East Trent
Northern Ireland Manley Schmidt 1965-05-11 Kautzerside
Northern Ireland Rahul Bechtelar 2004-11-20 Celiafurt
England Lea Schmidt 1952-03-07 Keeblerberg
Scotland Hulda Gerhold 1958-09-19 New Velvaburgh
Wales Estella Boyle 1996-11-24 New Rafaelview
Scotland Eudora Sawayn 1905-06-15 Mosestad
Scotland Norval D'Amore 2020-08-08 Izabellaton
Wales Julio Hamill 1953-12-24 Ezequielmouth
England Etha Collier 1966-07-23 Lake Arnoview
England Wyatt Green 1953-12-01 Fadelfurt
England Clotilde Hammes 1935-11-08 East Carroll
Wales Alexandre Paucek 1951-11-01 Hammesmouth
Wales Rosalee Reinger 1964-10-10 Eddport
England Esther Satterfield 1984-12-15 Lake Celinestad
Scotland Alessandra Orn 1965-02-19 North Cloyd
England Maye Davis 1991-09-07 Marcoshire
Northern Ireland Layne Schuster 1913-07-09 West Casimirbury
Scotland Isabelle Hand 1965-05-06 Port Ahmed
Scotland Keaton Price 1992-01-19 North Edna
Scotland Omari Swaniawski 1945-08-23 Wizaberg
Scotland Philip Pacocha 2011-12-20 South Dougside
England Maddison VonRueden 1980-08-21 Strosinshire
Wales Lorena Howe 1964-12-08 East Carolyn
Wales Bulah Flatley 2001-08-10 Kunzehaven
Scotland Demetrius Nader 1949-04-03 East Kassandra
Northern Ireland Catharine Vandervort 1919-04-16 Daretown
Wales Nolan Parker 1965-02-04 Westside
England Toni Walter 1964-11-17 Dollystad
England Bryce Schaefer 1910-06-27 New Aric
Scotland Keon Barton 1949-09-28 East Isom
England Kyler Gulgowski 2026-02-18 New Lewistown
Wales Kadin Ziemann 1953-02-13 Percyburgh
Scotland Lorenza Oberbrunner 1999-04-02 Hirthestad
Wales Arely Bernier 1990-06-14 Lakinburgh
England Ulices Gorczany 1925-09-09 Pacochaville
Scotland Keyshawn Cole 2009-05-16 Howefurt
Scotland Jeanette Prohaska 2008-11-11 South Corrineview
Scotland Jonathan Bosco 1988-03-21 Nicklausshire
England Bret Cronin 1946-09-26 Lake Lempifort

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">Scotland</td>
      <td role="cell">Chelsea</td>
      <td role="cell">Ortiz</td>
      <td data-value="-1842048000000" role="cell" class="epp-ar">1911-08-19</td>
      <td role="cell">North Shaun</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Garrett</td>
      <td role="cell">Conn</td>
      <td data-value="-1654300800000" role="cell" class="epp-ar">1917-07-31</td>
      <td role="cell">Lake Elwynmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Rusty</td>
      <td role="cell">Bode</td>
      <td data-value="1228176000000" role="cell" class="epp-ar">2008-12-02</td>
      <td role="cell">New Joshua</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Kathlyn</td>
      <td role="cell">Kris</td>
      <td data-value="-167961600000" role="cell" class="epp-ar">1964-09-05</td>
      <td role="cell">New Paige</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Carolyne</td>
      <td role="cell">Feil</td>
      <td data-value="602726400000" role="cell" class="epp-ar">1989-02-06</td>
      <td role="cell">Koelpinstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Jaquelin</td>
      <td role="cell">Jacobson</td>
      <td data-value="-1788825600000" role="cell" class="epp-ar">1913-04-26</td>
      <td role="cell">Kuhnfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jorge</td>
      <td role="cell">Terry</td>
      <td data-value="1556668800000" role="cell" class="epp-ar">2019-05-01</td>
      <td role="cell">Jarenland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Judge</td>
      <td role="cell">Dach</td>
      <td data-value="-740275200000" role="cell" class="epp-ar">1946-07-18</td>
      <td role="cell">Nicoleberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Freddy</td>
      <td role="cell">Batz</td>
      <td data-value="1209081600000" role="cell" class="epp-ar">2008-04-25</td>
      <td role="cell">Douglasmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Ben</td>
      <td role="cell">Pacocha</td>
      <td data-value="-312249600000" role="cell" class="epp-ar">1960-02-09</td>
      <td role="cell">Lake Ana</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jerrod</td>
      <td role="cell">Parker</td>
      <td data-value="1148256000000" role="cell" class="epp-ar">2006-05-22</td>
      <td role="cell">East Trent</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Manley</td>
      <td role="cell">Schmidt</td>
      <td data-value="-146534400000" role="cell" class="epp-ar">1965-05-11</td>
      <td role="cell">Kautzerside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Rahul</td>
      <td role="cell">Bechtelar</td>
      <td data-value="1100908800000" role="cell" class="epp-ar">2004-11-20</td>
      <td role="cell">Celiafurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Lea</td>
      <td role="cell">Schmidt</td>
      <td data-value="-562377600000" role="cell" class="epp-ar">1952-03-07</td>
      <td role="cell">Keeblerberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Hulda</td>
      <td role="cell">Gerhold</td>
      <td data-value="-356140800000" role="cell" class="epp-ar">1958-09-19</td>
      <td role="cell">New Velvaburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Estella</td>
      <td role="cell">Boyle</td>
      <td data-value="848793600000" role="cell" class="epp-ar">1996-11-24</td>
      <td role="cell">New Rafaelview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Eudora</td>
      <td role="cell">Sawayn</td>
      <td data-value="-2036966400000" role="cell" class="epp-ar">1905-06-15</td>
      <td role="cell">Mosestad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Norval</td>
      <td role="cell">D'Amore</td>
      <td data-value="1596844800000" role="cell" class="epp-ar">2020-08-08</td>
      <td role="cell">Izabellaton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Julio</td>
      <td role="cell">Hamill</td>
      <td data-value="-505612800000" role="cell" class="epp-ar">1953-12-24</td>
      <td role="cell">Ezequielmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Etha</td>
      <td role="cell">Collier</td>
      <td data-value="-108691200000" role="cell" class="epp-ar">1966-07-23</td>
      <td role="cell">Lake Arnoview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Wyatt</td>
      <td role="cell">Green</td>
      <td data-value="-507600000000" role="cell" class="epp-ar">1953-12-01</td>
      <td role="cell">Fadelfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Clotilde</td>
      <td role="cell">Hammes</td>
      <td data-value="-1077667200000" role="cell" class="epp-ar">1935-11-08</td>
      <td role="cell">East Carroll</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Alexandre</td>
      <td role="cell">Paucek</td>
      <td data-value="-573350400000" role="cell" class="epp-ar">1951-11-01</td>
      <td role="cell">Hammesmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Rosalee</td>
      <td role="cell">Reinger</td>
      <td data-value="-164937600000" role="cell" class="epp-ar">1964-10-10</td>
      <td role="cell">Eddport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Esther</td>
      <td role="cell">Satterfield</td>
      <td data-value="471916800000" role="cell" class="epp-ar">1984-12-15</td>
      <td role="cell">Lake Celinestad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Alessandra</td>
      <td role="cell">Orn</td>
      <td data-value="-153532800000" role="cell" class="epp-ar">1965-02-19</td>
      <td role="cell">North Cloyd</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Maye</td>
      <td role="cell">Davis</td>
      <td data-value="684201600000" role="cell" class="epp-ar">1991-09-07</td>
      <td role="cell">Marcoshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Layne</td>
      <td role="cell">Schuster</td>
      <td data-value="-1782432000000" role="cell" class="epp-ar">1913-07-09</td>
      <td role="cell">West Casimirbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Isabelle</td>
      <td role="cell">Hand</td>
      <td data-value="-146966400000" role="cell" class="epp-ar">1965-05-06</td>
      <td role="cell">Port Ahmed</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Keaton</td>
      <td role="cell">Price</td>
      <td data-value="695779200000" role="cell" class="epp-ar">1992-01-19</td>
      <td role="cell">North Edna</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Omari</td>
      <td role="cell">Swaniawski</td>
      <td data-value="-768700800000" role="cell" class="epp-ar">1945-08-23</td>
      <td role="cell">Wizaberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Philip</td>
      <td role="cell">Pacocha</td>
      <td data-value="1324339200000" role="cell" class="epp-ar">2011-12-20</td>
      <td role="cell">South Dougside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Maddison</td>
      <td role="cell">VonRueden</td>
      <td data-value="335664000000" role="cell" class="epp-ar">1980-08-21</td>
      <td role="cell">Strosinshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Lorena</td>
      <td role="cell">Howe</td>
      <td data-value="-159840000000" role="cell" class="epp-ar">1964-12-08</td>
      <td role="cell">East Carolyn</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Bulah</td>
      <td role="cell">Flatley</td>
      <td data-value="997401600000" role="cell" class="epp-ar">2001-08-10</td>
      <td role="cell">Kunzehaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Demetrius</td>
      <td role="cell">Nader</td>
      <td data-value="-654739200000" role="cell" class="epp-ar">1949-04-03</td>
      <td role="cell">East Kassandra</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Catharine</td>
      <td role="cell">Vandervort</td>
      <td data-value="-1600387200000" role="cell" class="epp-ar">1919-04-16</td>
      <td role="cell">Daretown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Nolan</td>
      <td role="cell">Parker</td>
      <td data-value="-154828800000" role="cell" class="epp-ar">1965-02-04</td>
      <td role="cell">Westside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Toni</td>
      <td role="cell">Walter</td>
      <td data-value="-161654400000" role="cell" class="epp-ar">1964-11-17</td>
      <td role="cell">Dollystad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Bryce</td>
      <td role="cell">Schaefer</td>
      <td data-value="-1878163200000" role="cell" class="epp-ar">1910-06-27</td>
      <td role="cell">New Aric</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Keon</td>
      <td role="cell">Barton</td>
      <td data-value="-639360000000" role="cell" class="epp-ar">1949-09-28</td>
      <td role="cell">East Isom</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Kyler</td>
      <td role="cell">Gulgowski</td>
      <td data-value="1771372800000" role="cell" class="epp-ar">2026-02-18</td>
      <td role="cell">New Lewistown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Kadin</td>
      <td role="cell">Ziemann</td>
      <td data-value="-532742400000" role="cell" class="epp-ar">1953-02-13</td>
      <td role="cell">Percyburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Lorenza</td>
      <td role="cell">Oberbrunner</td>
      <td data-value="923011200000" role="cell" class="epp-ar">1999-04-02</td>
      <td role="cell">Hirthestad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Arely</td>
      <td role="cell">Bernier</td>
      <td data-value="645321600000" role="cell" class="epp-ar">1990-06-14</td>
      <td role="cell">Lakinburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Ulices</td>
      <td role="cell">Gorczany</td>
      <td data-value="-1398384000000" role="cell" class="epp-ar">1925-09-09</td>
      <td role="cell">Pacochaville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Keyshawn</td>
      <td role="cell">Cole</td>
      <td data-value="1242432000000" role="cell" class="epp-ar">2009-05-16</td>
      <td role="cell">Howefurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jeanette</td>
      <td role="cell">Prohaska</td>
      <td data-value="1226361600000" role="cell" class="epp-ar">2008-11-11</td>
      <td role="cell">South Corrineview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jonathan</td>
      <td role="cell">Bosco</td>
      <td data-value="574905600000" role="cell" class="epp-ar">1988-03-21</td>
      <td role="cell">Nicklausshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Bret</td>
      <td role="cell">Cronin</td>
      <td data-value="-734227200000" role="cell" class="epp-ar">1946-09-26</td>
      <td role="cell">Lake Lempifort</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;
}