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 Retha Buckridge 1964-12-31 North Silas
England Tevin Harber 1964-06-22 New Dangelofort
Scotland Camden Witting 2015-03-22 Luciennemouth
Wales Beryl Hermiston 1937-10-20 West Selena
England Paige Wiza 1964-05-20 Marquardtport
Northern Ireland Tyler Grimes 1903-04-28 Grahamberg
Northern Ireland Gaetano Gislason 1995-08-06 West Delfina
Scotland Ramona Heller 1937-12-13 Fritschland
England Blanche Davis 1985-06-25 Lake Bethelside
Scotland Vivien Armstrong 1965-01-15 New Amybury
Northern Ireland Concepcion Franecki 1977-11-25 Hauckburgh
Northern Ireland Amara Kling 1979-11-21 East Laron
Scotland Deron Armstrong 1920-08-07 Lake Eden
Northern Ireland Elizabeth Grady 1906-10-05 Carterville
Northern Ireland Rollin Buckridge 1945-05-16 New Lolachester
Northern Ireland Rose Monahan 1958-04-28 Nicklausville
England Toby Steuber 1915-03-01 Auroretown
England Fiona Wisoky 1964-10-26 Dibbertstad
England Maximo Johnson 1958-05-10 Johnsville
Wales Katelyn Herman 1994-07-04 Ottiliehaven
England Kaylie Price 1989-02-20 Dachside
Wales Hubert Haley 1998-03-18 Kuhichaven
Northern Ireland Mason Thompson 1965-02-25 Abernathyland
Wales Izabella Mertz 1981-05-08 West Zulaburgh
England Bernhard Zboncak 1924-03-06 Wintheiserside
England Salvatore Witting 1972-10-18 Lake Josianne
Wales Lottie Torphy 1942-02-12 Harmonton
Scotland Meredith Ritchie 1982-08-23 North Bruce
Northern Ireland Lonny Grimes 1984-03-10 North Stone
Scotland Maegan Rosenbaum 1976-05-09 Port Tommieburgh
England Marietta Casper 2026-04-07 Hackettfort
England Kyle Watsica 1913-02-12 Nikolausfurt
Northern Ireland Dayton Rippin 1945-05-25 South Franciscabury
Scotland Myra Larson 1987-08-19 New Madelynburgh
Wales Mark Quigley 1965-08-29 Port Theron
Wales Nolan Treutel 1975-05-14 South Hanna
Wales Charley Jast 1961-11-17 Kuphalchester
Wales Zachery Murazik 1992-05-02 Jakubowskibury
England Lila Pacocha 1964-06-07 Dellmouth
Wales Garrick Haley 2021-08-31 East Colby
England Travon Cassin 1957-02-13 Mayerside
England Nannie Raynor 1977-08-15 East Candelario
Wales Domenico Turner 1918-04-19 South Virgie
Northern Ireland Brook Stehr 1932-05-10 New Emmabury
England Elenora Lang 1968-09-19 Corkerymouth
Scotland Eveline Conn 1947-05-05 Lake Aurelioside
Scotland Maribel Bergnaum 1999-07-25 Lake Pablotown
Northern Ireland Monica Rippin 1966-10-21 Robertsport
Wales Nettie Macejkovic 2017-10-20 South Hellenside
Scotland Miles Thiel 2017-06-29 Nonaport

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">Retha</td>
      <td role="cell">Buckridge</td>
      <td data-value="-157852800000" role="cell" class="epp-ar">1964-12-31</td>
      <td role="cell">North Silas</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Tevin</td>
      <td role="cell">Harber</td>
      <td data-value="-174441600000" role="cell" class="epp-ar">1964-06-22</td>
      <td role="cell">New Dangelofort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Camden</td>
      <td role="cell">Witting</td>
      <td data-value="1426982400000" role="cell" class="epp-ar">2015-03-22</td>
      <td role="cell">Luciennemouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Beryl</td>
      <td role="cell">Hermiston</td>
      <td data-value="-1016150400000" role="cell" class="epp-ar">1937-10-20</td>
      <td role="cell">West Selena</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Paige</td>
      <td role="cell">Wiza</td>
      <td data-value="-177292800000" role="cell" class="epp-ar">1964-05-20</td>
      <td role="cell">Marquardtport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Tyler</td>
      <td role="cell">Grimes</td>
      <td data-value="-2104272000000" role="cell" class="epp-ar">1903-04-28</td>
      <td role="cell">Grahamberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Gaetano</td>
      <td role="cell">Gislason</td>
      <td data-value="807667200000" role="cell" class="epp-ar">1995-08-06</td>
      <td role="cell">West Delfina</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Ramona</td>
      <td role="cell">Heller</td>
      <td data-value="-1011484800000" role="cell" class="epp-ar">1937-12-13</td>
      <td role="cell">Fritschland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Blanche</td>
      <td role="cell">Davis</td>
      <td data-value="488505600000" role="cell" class="epp-ar">1985-06-25</td>
      <td role="cell">Lake Bethelside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Vivien</td>
      <td role="cell">Armstrong</td>
      <td data-value="-156556800000" role="cell" class="epp-ar">1965-01-15</td>
      <td role="cell">New Amybury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Concepcion</td>
      <td role="cell">Franecki</td>
      <td data-value="249264000000" role="cell" class="epp-ar">1977-11-25</td>
      <td role="cell">Hauckburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Amara</td>
      <td role="cell">Kling</td>
      <td data-value="311990400000" role="cell" class="epp-ar">1979-11-21</td>
      <td role="cell">East Laron</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Deron</td>
      <td role="cell">Armstrong</td>
      <td data-value="-1559001600000" role="cell" class="epp-ar">1920-08-07</td>
      <td role="cell">Lake Eden</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Elizabeth</td>
      <td role="cell">Grady</td>
      <td data-value="-1995753600000" role="cell" class="epp-ar">1906-10-05</td>
      <td role="cell">Carterville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Rollin</td>
      <td role="cell">Buckridge</td>
      <td data-value="-777254400000" role="cell" class="epp-ar">1945-05-16</td>
      <td role="cell">New Lolachester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Rose</td>
      <td role="cell">Monahan</td>
      <td data-value="-368582400000" role="cell" class="epp-ar">1958-04-28</td>
      <td role="cell">Nicklausville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Toby</td>
      <td role="cell">Steuber</td>
      <td data-value="-1730592000000" role="cell" class="epp-ar">1915-03-01</td>
      <td role="cell">Auroretown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Fiona</td>
      <td role="cell">Wisoky</td>
      <td data-value="-163555200000" role="cell" class="epp-ar">1964-10-26</td>
      <td role="cell">Dibbertstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Maximo</td>
      <td role="cell">Johnson</td>
      <td data-value="-367545600000" role="cell" class="epp-ar">1958-05-10</td>
      <td role="cell">Johnsville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Katelyn</td>
      <td role="cell">Herman</td>
      <td data-value="773280000000" role="cell" class="epp-ar">1994-07-04</td>
      <td role="cell">Ottiliehaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Kaylie</td>
      <td role="cell">Price</td>
      <td data-value="603936000000" role="cell" class="epp-ar">1989-02-20</td>
      <td role="cell">Dachside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Hubert</td>
      <td role="cell">Haley</td>
      <td data-value="890179200000" role="cell" class="epp-ar">1998-03-18</td>
      <td role="cell">Kuhichaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Mason</td>
      <td role="cell">Thompson</td>
      <td data-value="-153014400000" role="cell" class="epp-ar">1965-02-25</td>
      <td role="cell">Abernathyland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Izabella</td>
      <td role="cell">Mertz</td>
      <td data-value="358128000000" role="cell" class="epp-ar">1981-05-08</td>
      <td role="cell">West Zulaburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Bernhard</td>
      <td role="cell">Zboncak</td>
      <td data-value="-1446076800000" role="cell" class="epp-ar">1924-03-06</td>
      <td role="cell">Wintheiserside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Salvatore</td>
      <td role="cell">Witting</td>
      <td data-value="88214400000" role="cell" class="epp-ar">1972-10-18</td>
      <td role="cell">Lake Josianne</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Lottie</td>
      <td role="cell">Torphy</td>
      <td data-value="-879984000000" role="cell" class="epp-ar">1942-02-12</td>
      <td role="cell">Harmonton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Meredith</td>
      <td role="cell">Ritchie</td>
      <td data-value="398908800000" role="cell" class="epp-ar">1982-08-23</td>
      <td role="cell">North Bruce</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Lonny</td>
      <td role="cell">Grimes</td>
      <td data-value="447724800000" role="cell" class="epp-ar">1984-03-10</td>
      <td role="cell">North Stone</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Maegan</td>
      <td role="cell">Rosenbaum</td>
      <td data-value="200448000000" role="cell" class="epp-ar">1976-05-09</td>
      <td role="cell">Port Tommieburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Marietta</td>
      <td role="cell">Casper</td>
      <td data-value="1775520000000" role="cell" class="epp-ar">2026-04-07</td>
      <td role="cell">Hackettfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Kyle</td>
      <td role="cell">Watsica</td>
      <td data-value="-1795132800000" role="cell" class="epp-ar">1913-02-12</td>
      <td role="cell">Nikolausfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Dayton</td>
      <td role="cell">Rippin</td>
      <td data-value="-776476800000" role="cell" class="epp-ar">1945-05-25</td>
      <td role="cell">South Franciscabury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Myra</td>
      <td role="cell">Larson</td>
      <td data-value="556329600000" role="cell" class="epp-ar">1987-08-19</td>
      <td role="cell">New Madelynburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Mark</td>
      <td role="cell">Quigley</td>
      <td data-value="-137030400000" role="cell" class="epp-ar">1965-08-29</td>
      <td role="cell">Port Theron</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Nolan</td>
      <td role="cell">Treutel</td>
      <td data-value="169257600000" role="cell" class="epp-ar">1975-05-14</td>
      <td role="cell">South Hanna</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Charley</td>
      <td role="cell">Jast</td>
      <td data-value="-256348800000" role="cell" class="epp-ar">1961-11-17</td>
      <td role="cell">Kuphalchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Zachery</td>
      <td role="cell">Murazik</td>
      <td data-value="704764800000" role="cell" class="epp-ar">1992-05-02</td>
      <td role="cell">Jakubowskibury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Lila</td>
      <td role="cell">Pacocha</td>
      <td data-value="-175737600000" role="cell" class="epp-ar">1964-06-07</td>
      <td role="cell">Dellmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Garrick</td>
      <td role="cell">Haley</td>
      <td data-value="1630368000000" role="cell" class="epp-ar">2021-08-31</td>
      <td role="cell">East Colby</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Travon</td>
      <td role="cell">Cassin</td>
      <td data-value="-406512000000" role="cell" class="epp-ar">1957-02-13</td>
      <td role="cell">Mayerside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Nannie</td>
      <td role="cell">Raynor</td>
      <td data-value="240451200000" role="cell" class="epp-ar">1977-08-15</td>
      <td role="cell">East Candelario</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Domenico</td>
      <td role="cell">Turner</td>
      <td data-value="-1631664000000" role="cell" class="epp-ar">1918-04-19</td>
      <td role="cell">South Virgie</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Brook</td>
      <td role="cell">Stehr</td>
      <td data-value="-1188000000000" role="cell" class="epp-ar">1932-05-10</td>
      <td role="cell">New Emmabury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Elenora</td>
      <td role="cell">Lang</td>
      <td data-value="-40521600000" role="cell" class="epp-ar">1968-09-19</td>
      <td role="cell">Corkerymouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Eveline</td>
      <td role="cell">Conn</td>
      <td data-value="-715132800000" role="cell" class="epp-ar">1947-05-05</td>
      <td role="cell">Lake Aurelioside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Maribel</td>
      <td role="cell">Bergnaum</td>
      <td data-value="932860800000" role="cell" class="epp-ar">1999-07-25</td>
      <td role="cell">Lake Pablotown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Monica</td>
      <td role="cell">Rippin</td>
      <td data-value="-100915200000" role="cell" class="epp-ar">1966-10-21</td>
      <td role="cell">Robertsport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Nettie</td>
      <td role="cell">Macejkovic</td>
      <td data-value="1508457600000" role="cell" class="epp-ar">2017-10-20</td>
      <td role="cell">South Hellenside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Miles</td>
      <td role="cell">Thiel</td>
      <td data-value="1498694400000" role="cell" class="epp-ar">2017-06-29</td>
      <td role="cell">Nonaport</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;
}