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
England Diana Schaden 1940-11-28 West Kathleentown
Northern Ireland Shanel Ruecker 1952-09-06 New Enosview
Northern Ireland Emmanuel Schinner 1959-03-04 New Rogerston
Northern Ireland Sammie Ward 1933-07-12 Port Maymie
Wales Coy Gutkowski 1963-10-22 Dareton
England Emmitt Mann 2011-02-27 West Joanytown
Northern Ireland Davon Ankunding 2021-09-26 Willaport
Scotland Denis Bins 1940-05-25 Hollisbury
Northern Ireland Nia Crist 1959-06-05 Port Delbert
Wales Aliyah Jewess 1964-12-19 Lake Raeganmouth
Wales Emanuel Bruen 2009-09-22 Alfredaport
Northern Ireland Queen Howell 1952-05-08 North Marcellus
England Dustin Ratke 1940-02-02 Jaclynville
England Sarina Donnelly 1964-12-09 South Zackary
Northern Ireland Fredrick Beier 1964-05-02 Dickensbury
England Percy Moen 1952-06-19 North Edyth
England George Hoppe 2003-07-22 New Isadoremouth
England Burley Prohaska 1936-05-05 Port Alvina
Scotland Etha O'Kon 1917-10-01 Gutmannstad
Scotland Ryleigh Abernathy 1968-07-13 Lindport
Wales Dorthy Ernser 1925-03-16 Hannafurt
England Hannah Crooks 1982-07-24 Schillerfurt
Scotland Deron Emard 1924-07-26 Lurashire
Scotland Marvin Lynch 1926-01-01 South Ransomport
Scotland Domenick Paucek 1941-12-06 North Darien
Wales Elvie Schiller 1940-12-30 Prosaccomouth
Northern Ireland Guy Bins 1905-02-11 Torphyville
Wales Carlie Jacobs 1916-09-20 Marisamouth
England Burnice Vandervort 1998-07-10 New Geoffrey
Northern Ireland Mercedes Mraz 2003-03-20 Port Melissa
Northern Ireland Madalyn Cassin 1965-01-26 New Margarett
Scotland Hildegard Brakus 1976-06-27 Parkerport
England Pablo Adams 1993-05-28 West Emeraldbury
Northern Ireland Amira Luettgen 1980-08-11 South Birdieport
Scotland Monserrat Marks 2001-10-02 Dewittland
England Mina Fadel 1964-12-01 North Nella
Wales Trey Jerde 1947-07-23 South Mia
Scotland Bobby Price 1981-11-04 Boscoburgh
Wales Brenda Borer 2018-05-30 Smithamshire
Scotland Pat O'Kon 2024-12-27 West Nichole
Wales Zetta Dietrich 1956-12-15 Shanahanborough
Wales Rhoda Reynolds 1983-04-08 Maciborough
England Wade Ruecker 1939-03-28 Lake Lavadabury
Wales Phyllis Wolf 1946-12-26 West Lesterchester
England Dorothy Volkman 1921-05-19 New Thomas
Northern Ireland Rhiannon Littel 1999-05-10 Alhaven
Wales Joany Bode 1969-07-11 Merlinton
Northern Ireland Felicia Connelly 1949-05-31 Hintztown
Scotland Jade Stroman 1986-12-25 Aurelieland
Wales Laron Gleason 1981-08-17 South Mia

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">Diana</td>
      <td role="cell">Schaden</td>
      <td data-value="-918086400000" role="cell" class="epp-ar">1940-11-28</td>
      <td role="cell">West Kathleentown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Shanel</td>
      <td role="cell">Ruecker</td>
      <td data-value="-546566400000" role="cell" class="epp-ar">1952-09-06</td>
      <td role="cell">New Enosview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Emmanuel</td>
      <td role="cell">Schinner</td>
      <td data-value="-341798400000" role="cell" class="epp-ar">1959-03-04</td>
      <td role="cell">New Rogerston</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Sammie</td>
      <td role="cell">Ward</td>
      <td data-value="-1151020800000" role="cell" class="epp-ar">1933-07-12</td>
      <td role="cell">Port Maymie</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Coy</td>
      <td role="cell">Gutkowski</td>
      <td data-value="-195523200000" role="cell" class="epp-ar">1963-10-22</td>
      <td role="cell">Dareton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Emmitt</td>
      <td role="cell">Mann</td>
      <td data-value="1298764800000" role="cell" class="epp-ar">2011-02-27</td>
      <td role="cell">West Joanytown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Davon</td>
      <td role="cell">Ankunding</td>
      <td data-value="1632614400000" role="cell" class="epp-ar">2021-09-26</td>
      <td role="cell">Willaport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Denis</td>
      <td role="cell">Bins</td>
      <td data-value="-934243200000" role="cell" class="epp-ar">1940-05-25</td>
      <td role="cell">Hollisbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Nia</td>
      <td role="cell">Crist</td>
      <td data-value="-333763200000" role="cell" class="epp-ar">1959-06-05</td>
      <td role="cell">Port Delbert</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Aliyah</td>
      <td role="cell">Jewess</td>
      <td data-value="-158889600000" role="cell" class="epp-ar">1964-12-19</td>
      <td role="cell">Lake Raeganmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Emanuel</td>
      <td role="cell">Bruen</td>
      <td data-value="1253577600000" role="cell" class="epp-ar">2009-09-22</td>
      <td role="cell">Alfredaport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Queen</td>
      <td role="cell">Howell</td>
      <td data-value="-557020800000" role="cell" class="epp-ar">1952-05-08</td>
      <td role="cell">North Marcellus</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Dustin</td>
      <td role="cell">Ratke</td>
      <td data-value="-944006400000" role="cell" class="epp-ar">1940-02-02</td>
      <td role="cell">Jaclynville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Sarina</td>
      <td role="cell">Donnelly</td>
      <td data-value="-159753600000" role="cell" class="epp-ar">1964-12-09</td>
      <td role="cell">South Zackary</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Fredrick</td>
      <td role="cell">Beier</td>
      <td data-value="-178848000000" role="cell" class="epp-ar">1964-05-02</td>
      <td role="cell">Dickensbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Percy</td>
      <td role="cell">Moen</td>
      <td data-value="-553392000000" role="cell" class="epp-ar">1952-06-19</td>
      <td role="cell">North Edyth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">George</td>
      <td role="cell">Hoppe</td>
      <td data-value="1058832000000" role="cell" class="epp-ar">2003-07-22</td>
      <td role="cell">New Isadoremouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Burley</td>
      <td role="cell">Prohaska</td>
      <td data-value="-1062201600000" role="cell" class="epp-ar">1936-05-05</td>
      <td role="cell">Port Alvina</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Etha</td>
      <td role="cell">O'Kon</td>
      <td data-value="-1648944000000" role="cell" class="epp-ar">1917-10-01</td>
      <td role="cell">Gutmannstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Ryleigh</td>
      <td role="cell">Abernathy</td>
      <td data-value="-46396800000" role="cell" class="epp-ar">1968-07-13</td>
      <td role="cell">Lindport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Dorthy</td>
      <td role="cell">Ernser</td>
      <td data-value="-1413676800000" role="cell" class="epp-ar">1925-03-16</td>
      <td role="cell">Hannafurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Hannah</td>
      <td role="cell">Crooks</td>
      <td data-value="396316800000" role="cell" class="epp-ar">1982-07-24</td>
      <td role="cell">Schillerfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Deron</td>
      <td role="cell">Emard</td>
      <td data-value="-1433808000000" role="cell" class="epp-ar">1924-07-26</td>
      <td role="cell">Lurashire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Marvin</td>
      <td role="cell">Lynch</td>
      <td data-value="-1388534400000" role="cell" class="epp-ar">1926-01-01</td>
      <td role="cell">South Ransomport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Domenick</td>
      <td role="cell">Paucek</td>
      <td data-value="-885859200000" role="cell" class="epp-ar">1941-12-06</td>
      <td role="cell">North Darien</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Elvie</td>
      <td role="cell">Schiller</td>
      <td data-value="-915321600000" role="cell" class="epp-ar">1940-12-30</td>
      <td role="cell">Prosaccomouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Guy</td>
      <td role="cell">Bins</td>
      <td data-value="-2047680000000" role="cell" class="epp-ar">1905-02-11</td>
      <td role="cell">Torphyville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Carlie</td>
      <td role="cell">Jacobs</td>
      <td data-value="-1681430400000" role="cell" class="epp-ar">1916-09-20</td>
      <td role="cell">Marisamouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Burnice</td>
      <td role="cell">Vandervort</td>
      <td data-value="900028800000" role="cell" class="epp-ar">1998-07-10</td>
      <td role="cell">New Geoffrey</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Mercedes</td>
      <td role="cell">Mraz</td>
      <td data-value="1048118400000" role="cell" class="epp-ar">2003-03-20</td>
      <td role="cell">Port Melissa</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Madalyn</td>
      <td role="cell">Cassin</td>
      <td data-value="-155606400000" role="cell" class="epp-ar">1965-01-26</td>
      <td role="cell">New Margarett</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Hildegard</td>
      <td role="cell">Brakus</td>
      <td data-value="204681600000" role="cell" class="epp-ar">1976-06-27</td>
      <td role="cell">Parkerport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Pablo</td>
      <td role="cell">Adams</td>
      <td data-value="738547200000" role="cell" class="epp-ar">1993-05-28</td>
      <td role="cell">West Emeraldbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Amira</td>
      <td role="cell">Luettgen</td>
      <td data-value="334800000000" role="cell" class="epp-ar">1980-08-11</td>
      <td role="cell">South Birdieport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Monserrat</td>
      <td role="cell">Marks</td>
      <td data-value="1001980800000" role="cell" class="epp-ar">2001-10-02</td>
      <td role="cell">Dewittland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Mina</td>
      <td role="cell">Fadel</td>
      <td data-value="-160444800000" role="cell" class="epp-ar">1964-12-01</td>
      <td role="cell">North Nella</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Trey</td>
      <td role="cell">Jerde</td>
      <td data-value="-708307200000" role="cell" class="epp-ar">1947-07-23</td>
      <td role="cell">South Mia</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Bobby</td>
      <td role="cell">Price</td>
      <td data-value="373680000000" role="cell" class="epp-ar">1981-11-04</td>
      <td role="cell">Boscoburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Brenda</td>
      <td role="cell">Borer</td>
      <td data-value="1527638400000" role="cell" class="epp-ar">2018-05-30</td>
      <td role="cell">Smithamshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Pat</td>
      <td role="cell">O'Kon</td>
      <td data-value="1735257600000" role="cell" class="epp-ar">2024-12-27</td>
      <td role="cell">West Nichole</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Zetta</td>
      <td role="cell">Dietrich</td>
      <td data-value="-411696000000" role="cell" class="epp-ar">1956-12-15</td>
      <td role="cell">Shanahanborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Rhoda</td>
      <td role="cell">Reynolds</td>
      <td data-value="418608000000" role="cell" class="epp-ar">1983-04-08</td>
      <td role="cell">Maciborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Wade</td>
      <td role="cell">Ruecker</td>
      <td data-value="-970876800000" role="cell" class="epp-ar">1939-03-28</td>
      <td role="cell">Lake Lavadabury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Phyllis</td>
      <td role="cell">Wolf</td>
      <td data-value="-726364800000" role="cell" class="epp-ar">1946-12-26</td>
      <td role="cell">West Lesterchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Dorothy</td>
      <td role="cell">Volkman</td>
      <td data-value="-1534377600000" role="cell" class="epp-ar">1921-05-19</td>
      <td role="cell">New Thomas</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Rhiannon</td>
      <td role="cell">Littel</td>
      <td data-value="926294400000" role="cell" class="epp-ar">1999-05-10</td>
      <td role="cell">Alhaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Joany</td>
      <td role="cell">Bode</td>
      <td data-value="-15033600000" role="cell" class="epp-ar">1969-07-11</td>
      <td role="cell">Merlinton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Felicia</td>
      <td role="cell">Connelly</td>
      <td data-value="-649728000000" role="cell" class="epp-ar">1949-05-31</td>
      <td role="cell">Hintztown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jade</td>
      <td role="cell">Stroman</td>
      <td data-value="535852800000" role="cell" class="epp-ar">1986-12-25</td>
      <td role="cell">Aurelieland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Laron</td>
      <td role="cell">Gleason</td>
      <td data-value="366854400000" role="cell" class="epp-ar">1981-08-17</td>
      <td role="cell">South Mia</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;
}