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
Wales Manuel Kunde 1967-04-21 Luettgenville
Scotland Lazaro Smitham 2019-08-22 West Bonnie
Wales Florine Funk 1977-09-17 Muellerport
England Mallie Torphy 1996-08-20 South Loganfurt
Northern Ireland Darwin Balistreri 1969-10-29 Eichmannside
Wales Martina Wyman 1990-05-11 North Nakia
Wales Dominic Frami 1964-09-29 Elroyland
Wales Bo Harris 1986-07-05 Goodwinton
Wales Mohammed Ferry 1957-04-24 Lake Genoveva
Scotland Sonia Hand 1964-09-01 South Elvis
Wales Abbigail Kirlin 1982-02-14 Swiftmouth
Scotland Kassandra McGlynn 2016-05-20 West Theaview
Scotland Louisa Tromp 1953-01-11 East Lolitaborough
Scotland Wilton Thiel 1934-06-17 Wilbertmouth
England Raina Borer 1964-03-18 Framiberg
Wales Hoyt Champlin 1972-01-24 Keenanstad
Scotland Jess Rippin 1948-05-31 Armstrongmouth
Wales Gustave Becker 1959-10-24 Port Bryanafurt
England Angela Sporer 1955-12-06 Filibertohaven
Northern Ireland Delbert Baumbach 1927-11-24 Lake Maegan
Wales Larry Turcotte 1999-10-29 Port Koby
Scotland Abner Pfannerstill 1929-01-19 Roweburgh
England Raoul Schumm 1944-08-05 North Zachariah
Wales Lilla Swaniawski 1943-01-15 West Eve
Wales Andres Bartell 1975-01-31 Cynthiaburgh
England Ariel McClure 1951-08-23 Strosinbury
England Josie Pouros 1984-02-15 Lake Eliseoton
Wales Adolph Kutch 1935-10-06 North Theodorefort
England Nicholaus Stehr 1946-06-25 New Selina
Northern Ireland Oran O'Conner 1915-07-29 Clintonshire
Wales Itzel O'Reilly 1983-08-04 West Emiliano
England Haskell Blanda 2019-03-12 South Cleora
Wales Keegan Kreiger 2019-11-22 Nitzscheville
Scotland Gilda Dickens 1946-12-17 Abagailton
Northern Ireland Arvel Anderson 1990-07-24 Zachariahtown
Scotland Dixie Zemlak 1976-12-27 Amparoville
England Nicole Renner 2010-01-02 Port Idellbury
Wales Mikayla Gleason 1938-03-14 Balistreriport
England Jerrold Stiedemann 1934-06-10 Kellybury
Wales Roel Hickle 1918-05-18 Hahnborough
England Vergie Raynor 1969-12-26 Rathfort
Scotland Ahmad Russel 1996-10-01 Gerardfurt
Scotland Steve Robel 1907-11-25 Lake Cordiebury
Northern Ireland Rickey Klein 1964-11-14 North Ricky
Scotland Merlin Jacobi 1953-05-06 West Kyra
Scotland Demarcus Purdy 1937-12-08 Mortonland
Scotland Hipolito Daniel 1958-07-16 North Bonniemouth
Northern Ireland Richard Roob 1967-05-12 Angelicaburgh
Wales Lucious Mohr 1972-10-16 Port Noemiview
Northern Ireland Kayden Schinner 2019-02-28 North Ricardostad

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">Wales</td>
      <td role="cell">Manuel</td>
      <td role="cell">Kunde</td>
      <td data-value="-85190400000" role="cell" class="epp-ar">1967-04-21</td>
      <td role="cell">Luettgenville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Lazaro</td>
      <td role="cell">Smitham</td>
      <td data-value="1566432000000" role="cell" class="epp-ar">2019-08-22</td>
      <td role="cell">West Bonnie</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Florine</td>
      <td role="cell">Funk</td>
      <td data-value="243302400000" role="cell" class="epp-ar">1977-09-17</td>
      <td role="cell">Muellerport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Mallie</td>
      <td role="cell">Torphy</td>
      <td data-value="840499200000" role="cell" class="epp-ar">1996-08-20</td>
      <td role="cell">South Loganfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Darwin</td>
      <td role="cell">Balistreri</td>
      <td data-value="-5529600000" role="cell" class="epp-ar">1969-10-29</td>
      <td role="cell">Eichmannside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Martina</td>
      <td role="cell">Wyman</td>
      <td data-value="642384000000" role="cell" class="epp-ar">1990-05-11</td>
      <td role="cell">North Nakia</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Dominic</td>
      <td role="cell">Frami</td>
      <td data-value="-165888000000" role="cell" class="epp-ar">1964-09-29</td>
      <td role="cell">Elroyland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Bo</td>
      <td role="cell">Harris</td>
      <td data-value="520905600000" role="cell" class="epp-ar">1986-07-05</td>
      <td role="cell">Goodwinton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Mohammed</td>
      <td role="cell">Ferry</td>
      <td data-value="-400464000000" role="cell" class="epp-ar">1957-04-24</td>
      <td role="cell">Lake Genoveva</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Sonia</td>
      <td role="cell">Hand</td>
      <td data-value="-168307200000" role="cell" class="epp-ar">1964-09-01</td>
      <td role="cell">South Elvis</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Abbigail</td>
      <td role="cell">Kirlin</td>
      <td data-value="382492800000" role="cell" class="epp-ar">1982-02-14</td>
      <td role="cell">Swiftmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Kassandra</td>
      <td role="cell">McGlynn</td>
      <td data-value="1463702400000" role="cell" class="epp-ar">2016-05-20</td>
      <td role="cell">West Theaview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Louisa</td>
      <td role="cell">Tromp</td>
      <td data-value="-535593600000" role="cell" class="epp-ar">1953-01-11</td>
      <td role="cell">East Lolitaborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Wilton</td>
      <td role="cell">Thiel</td>
      <td data-value="-1121644800000" role="cell" class="epp-ar">1934-06-17</td>
      <td role="cell">Wilbertmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Raina</td>
      <td role="cell">Borer</td>
      <td data-value="-182736000000" role="cell" class="epp-ar">1964-03-18</td>
      <td role="cell">Framiberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Hoyt</td>
      <td role="cell">Champlin</td>
      <td data-value="65059200000" role="cell" class="epp-ar">1972-01-24</td>
      <td role="cell">Keenanstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jess</td>
      <td role="cell">Rippin</td>
      <td data-value="-681264000000" role="cell" class="epp-ar">1948-05-31</td>
      <td role="cell">Armstrongmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Gustave</td>
      <td role="cell">Becker</td>
      <td data-value="-321580800000" role="cell" class="epp-ar">1959-10-24</td>
      <td role="cell">Port Bryanafurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Angela</td>
      <td role="cell">Sporer</td>
      <td data-value="-444096000000" role="cell" class="epp-ar">1955-12-06</td>
      <td role="cell">Filibertohaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Delbert</td>
      <td role="cell">Baumbach</td>
      <td data-value="-1328745600000" role="cell" class="epp-ar">1927-11-24</td>
      <td role="cell">Lake Maegan</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Larry</td>
      <td role="cell">Turcotte</td>
      <td data-value="941155200000" role="cell" class="epp-ar">1999-10-29</td>
      <td role="cell">Port Koby</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Abner</td>
      <td role="cell">Pfannerstill</td>
      <td data-value="-1292284800000" role="cell" class="epp-ar">1929-01-19</td>
      <td role="cell">Roweburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Raoul</td>
      <td role="cell">Schumm</td>
      <td data-value="-801792000000" role="cell" class="epp-ar">1944-08-05</td>
      <td role="cell">North Zachariah</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Lilla</td>
      <td role="cell">Swaniawski</td>
      <td data-value="-850867200000" role="cell" class="epp-ar">1943-01-15</td>
      <td role="cell">West Eve</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Andres</td>
      <td role="cell">Bartell</td>
      <td data-value="160358400000" role="cell" class="epp-ar">1975-01-31</td>
      <td role="cell">Cynthiaburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Ariel</td>
      <td role="cell">McClure</td>
      <td data-value="-579398400000" role="cell" class="epp-ar">1951-08-23</td>
      <td role="cell">Strosinbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Josie</td>
      <td role="cell">Pouros</td>
      <td data-value="445651200000" role="cell" class="epp-ar">1984-02-15</td>
      <td role="cell">Lake Eliseoton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Adolph</td>
      <td role="cell">Kutch</td>
      <td data-value="-1080518400000" role="cell" class="epp-ar">1935-10-06</td>
      <td role="cell">North Theodorefort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Nicholaus</td>
      <td role="cell">Stehr</td>
      <td data-value="-742262400000" role="cell" class="epp-ar">1946-06-25</td>
      <td role="cell">New Selina</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Oran</td>
      <td role="cell">O'Conner</td>
      <td data-value="-1717632000000" role="cell" class="epp-ar">1915-07-29</td>
      <td role="cell">Clintonshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Itzel</td>
      <td role="cell">O'Reilly</td>
      <td data-value="428803200000" role="cell" class="epp-ar">1983-08-04</td>
      <td role="cell">West Emiliano</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Haskell</td>
      <td role="cell">Blanda</td>
      <td data-value="1552348800000" role="cell" class="epp-ar">2019-03-12</td>
      <td role="cell">South Cleora</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Keegan</td>
      <td role="cell">Kreiger</td>
      <td data-value="1574380800000" role="cell" class="epp-ar">2019-11-22</td>
      <td role="cell">Nitzscheville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Gilda</td>
      <td role="cell">Dickens</td>
      <td data-value="-727142400000" role="cell" class="epp-ar">1946-12-17</td>
      <td role="cell">Abagailton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Arvel</td>
      <td role="cell">Anderson</td>
      <td data-value="648777600000" role="cell" class="epp-ar">1990-07-24</td>
      <td role="cell">Zachariahtown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Dixie</td>
      <td role="cell">Zemlak</td>
      <td data-value="220492800000" role="cell" class="epp-ar">1976-12-27</td>
      <td role="cell">Amparoville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Nicole</td>
      <td role="cell">Renner</td>
      <td data-value="1262390400000" role="cell" class="epp-ar">2010-01-02</td>
      <td role="cell">Port Idellbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Mikayla</td>
      <td role="cell">Gleason</td>
      <td data-value="-1003622400000" role="cell" class="epp-ar">1938-03-14</td>
      <td role="cell">Balistreriport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Jerrold</td>
      <td role="cell">Stiedemann</td>
      <td data-value="-1122249600000" role="cell" class="epp-ar">1934-06-10</td>
      <td role="cell">Kellybury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Roel</td>
      <td role="cell">Hickle</td>
      <td data-value="-1629158400000" role="cell" class="epp-ar">1918-05-18</td>
      <td role="cell">Hahnborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Vergie</td>
      <td role="cell">Raynor</td>
      <td data-value="-518400000" role="cell" class="epp-ar">1969-12-26</td>
      <td role="cell">Rathfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Ahmad</td>
      <td role="cell">Russel</td>
      <td data-value="844128000000" role="cell" class="epp-ar">1996-10-01</td>
      <td role="cell">Gerardfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Steve</td>
      <td role="cell">Robel</td>
      <td data-value="-1959811200000" role="cell" class="epp-ar">1907-11-25</td>
      <td role="cell">Lake Cordiebury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Rickey</td>
      <td role="cell">Klein</td>
      <td data-value="-161913600000" role="cell" class="epp-ar">1964-11-14</td>
      <td role="cell">North Ricky</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Merlin</td>
      <td role="cell">Jacobi</td>
      <td data-value="-525657600000" role="cell" class="epp-ar">1953-05-06</td>
      <td role="cell">West Kyra</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Demarcus</td>
      <td role="cell">Purdy</td>
      <td data-value="-1011916800000" role="cell" class="epp-ar">1937-12-08</td>
      <td role="cell">Mortonland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Hipolito</td>
      <td role="cell">Daniel</td>
      <td data-value="-361756800000" role="cell" class="epp-ar">1958-07-16</td>
      <td role="cell">North Bonniemouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Richard</td>
      <td role="cell">Roob</td>
      <td data-value="-83376000000" role="cell" class="epp-ar">1967-05-12</td>
      <td role="cell">Angelicaburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Lucious</td>
      <td role="cell">Mohr</td>
      <td data-value="88041600000" role="cell" class="epp-ar">1972-10-16</td>
      <td role="cell">Port Noemiview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Kayden</td>
      <td role="cell">Schinner</td>
      <td data-value="1551312000000" role="cell" class="epp-ar">2019-02-28</td>
      <td role="cell">North Ricardostad</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;
}