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 Shanelle Grimes 2024-02-23 Oswaldofurt
England Ryder Bartell 1978-04-16 Lake Diana
England Rosie Wyman 1992-09-27 North Sasha
England Zella Wilkinson 1964-09-05 North Raymondton
Northern Ireland Kattie Parker 1917-02-26 Maximillianchester
Northern Ireland Kristoffer Robel 1950-04-15 Agnesmouth
England Trenton Hirthe 2021-03-12 Bobbieport
England Sylvester Halvorson 2021-08-12 Annashire
Northern Ireland Juliana Kohler 1993-07-03 North Stacyborough
Wales Anissa Cassin 1924-09-08 Brekkemouth
England Neva Brown 1961-08-03 Port Cora
Northern Ireland Modesto Bahringer 1997-07-13 Douglasbury
Wales Jaquelin Turner 1920-07-20 Braunview
Scotland Foster Bartoletti 1913-08-05 Gutkowskiland
England Emil Denesik 1943-10-18 McKenziemouth
England Euna Crist 1964-09-02 North Dee
Wales Dave Zboncak 2015-12-09 Hodkiewiczstad
Wales Yesenia Gorczany 1974-09-02 West Emmanuelhaven
Northern Ireland Barton Hills 2024-07-17 South Misty
Wales Luther Stiedemann 2009-10-26 New Keshaun
Wales Carlos Ratke 1918-10-01 Faustinoport
Wales Ernesto Jerde 1977-02-21 East Camilla
England Gabe Buckridge 1968-06-16 East Stephenport
Wales Arthur Haag 1947-01-01 Jordanebury
Wales Estel Ratke 2010-06-14 Johnsview
England Madalyn Anderson 1918-12-05 Jaysonville
Wales Keara Schroeder 1940-07-31 West Liana
England Isac Ankunding 1964-10-30 East Masonmouth
Northern Ireland Pearl Mills 1947-08-15 West Vida
England Verlie Nicolas 2003-01-20 Port Angusport
Wales Tobin Gottlieb 1944-07-27 Antoinetteburgh
Scotland Melba Funk 1938-04-28 Port Dustin
Northern Ireland Henry Hoppe 1964-03-24 South Devon
Wales Thaddeus McCullough 1964-06-02 Bergeside
England Elisa McCullough 2006-11-27 Port Maurinestad
Scotland Opal Jacobs 1924-02-05 Hilpertmouth
England Jayda Hilll 1915-03-08 Lake Elijahtown
England Lola Brown 2026-01-07 Predovicbury
Northern Ireland Luisa Hudson 1945-11-17 South Candido
Wales Dimitri Effertz 1917-10-24 Gutmannland
Wales Jarred Streich 1938-01-22 New Meta
Wales Charley Bradtke 1907-12-19 Armstrongtown
Scotland Chelsea O'Kon 1976-06-28 Port Sadye
Wales Patience Hodkiewicz 1933-05-15 Antwanhaven
Wales Elyse Purdy 1980-12-15 Guidoshire
England Kirsten Hane 2022-10-30 Cormierburgh
Scotland Vincent Stiedemann 1914-07-14 Port Liam
Scotland Avery Price 1911-01-15 Clintonborough
Scotland Uriah Runolfsdottir 1973-04-26 Turcotteborough
Scotland Lucas Kirlin 2017-08-19 Prosaccoberg

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">Shanelle</td>
      <td role="cell">Grimes</td>
      <td data-value="1708646400000" role="cell" class="epp-ar">2024-02-23</td>
      <td role="cell">Oswaldofurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Ryder</td>
      <td role="cell">Bartell</td>
      <td data-value="261532800000" role="cell" class="epp-ar">1978-04-16</td>
      <td role="cell">Lake Diana</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Rosie</td>
      <td role="cell">Wyman</td>
      <td data-value="717552000000" role="cell" class="epp-ar">1992-09-27</td>
      <td role="cell">North Sasha</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Zella</td>
      <td role="cell">Wilkinson</td>
      <td data-value="-167961600000" role="cell" class="epp-ar">1964-09-05</td>
      <td role="cell">North Raymondton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Kattie</td>
      <td role="cell">Parker</td>
      <td data-value="-1667692800000" role="cell" class="epp-ar">1917-02-26</td>
      <td role="cell">Maximillianchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Kristoffer</td>
      <td role="cell">Robel</td>
      <td data-value="-622166400000" role="cell" class="epp-ar">1950-04-15</td>
      <td role="cell">Agnesmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Trenton</td>
      <td role="cell">Hirthe</td>
      <td data-value="1615507200000" role="cell" class="epp-ar">2021-03-12</td>
      <td role="cell">Bobbieport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Sylvester</td>
      <td role="cell">Halvorson</td>
      <td data-value="1628726400000" role="cell" class="epp-ar">2021-08-12</td>
      <td role="cell">Annashire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Juliana</td>
      <td role="cell">Kohler</td>
      <td data-value="741657600000" role="cell" class="epp-ar">1993-07-03</td>
      <td role="cell">North Stacyborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Anissa</td>
      <td role="cell">Cassin</td>
      <td data-value="-1430006400000" role="cell" class="epp-ar">1924-09-08</td>
      <td role="cell">Brekkemouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Neva</td>
      <td role="cell">Brown</td>
      <td data-value="-265507200000" role="cell" class="epp-ar">1961-08-03</td>
      <td role="cell">Port Cora</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Modesto</td>
      <td role="cell">Bahringer</td>
      <td data-value="868752000000" role="cell" class="epp-ar">1997-07-13</td>
      <td role="cell">Douglasbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Jaquelin</td>
      <td role="cell">Turner</td>
      <td data-value="-1560556800000" role="cell" class="epp-ar">1920-07-20</td>
      <td role="cell">Braunview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Foster</td>
      <td role="cell">Bartoletti</td>
      <td data-value="-1780099200000" role="cell" class="epp-ar">1913-08-05</td>
      <td role="cell">Gutkowskiland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Emil</td>
      <td role="cell">Denesik</td>
      <td data-value="-827020800000" role="cell" class="epp-ar">1943-10-18</td>
      <td role="cell">McKenziemouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Euna</td>
      <td role="cell">Crist</td>
      <td data-value="-168220800000" role="cell" class="epp-ar">1964-09-02</td>
      <td role="cell">North Dee</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Dave</td>
      <td role="cell">Zboncak</td>
      <td data-value="1449619200000" role="cell" class="epp-ar">2015-12-09</td>
      <td role="cell">Hodkiewiczstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Yesenia</td>
      <td role="cell">Gorczany</td>
      <td data-value="147312000000" role="cell" class="epp-ar">1974-09-02</td>
      <td role="cell">West Emmanuelhaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Barton</td>
      <td role="cell">Hills</td>
      <td data-value="1721174400000" role="cell" class="epp-ar">2024-07-17</td>
      <td role="cell">South Misty</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Luther</td>
      <td role="cell">Stiedemann</td>
      <td data-value="1256515200000" role="cell" class="epp-ar">2009-10-26</td>
      <td role="cell">New Keshaun</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Carlos</td>
      <td role="cell">Ratke</td>
      <td data-value="-1617408000000" role="cell" class="epp-ar">1918-10-01</td>
      <td role="cell">Faustinoport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Ernesto</td>
      <td role="cell">Jerde</td>
      <td data-value="225331200000" role="cell" class="epp-ar">1977-02-21</td>
      <td role="cell">East Camilla</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Gabe</td>
      <td role="cell">Buckridge</td>
      <td data-value="-48729600000" role="cell" class="epp-ar">1968-06-16</td>
      <td role="cell">East Stephenport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Arthur</td>
      <td role="cell">Haag</td>
      <td data-value="-725846400000" role="cell" class="epp-ar">1947-01-01</td>
      <td role="cell">Jordanebury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Estel</td>
      <td role="cell">Ratke</td>
      <td data-value="1276473600000" role="cell" class="epp-ar">2010-06-14</td>
      <td role="cell">Johnsview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Madalyn</td>
      <td role="cell">Anderson</td>
      <td data-value="-1611792000000" role="cell" class="epp-ar">1918-12-05</td>
      <td role="cell">Jaysonville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Keara</td>
      <td role="cell">Schroeder</td>
      <td data-value="-928454400000" role="cell" class="epp-ar">1940-07-31</td>
      <td role="cell">West Liana</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Isac</td>
      <td role="cell">Ankunding</td>
      <td data-value="-163209600000" role="cell" class="epp-ar">1964-10-30</td>
      <td role="cell">East Masonmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Pearl</td>
      <td role="cell">Mills</td>
      <td data-value="-706320000000" role="cell" class="epp-ar">1947-08-15</td>
      <td role="cell">West Vida</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Verlie</td>
      <td role="cell">Nicolas</td>
      <td data-value="1043020800000" role="cell" class="epp-ar">2003-01-20</td>
      <td role="cell">Port Angusport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Tobin</td>
      <td role="cell">Gottlieb</td>
      <td data-value="-802569600000" role="cell" class="epp-ar">1944-07-27</td>
      <td role="cell">Antoinetteburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Melba</td>
      <td role="cell">Funk</td>
      <td data-value="-999734400000" role="cell" class="epp-ar">1938-04-28</td>
      <td role="cell">Port Dustin</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Henry</td>
      <td role="cell">Hoppe</td>
      <td data-value="-182217600000" role="cell" class="epp-ar">1964-03-24</td>
      <td role="cell">South Devon</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Thaddeus</td>
      <td role="cell">McCullough</td>
      <td data-value="-176169600000" role="cell" class="epp-ar">1964-06-02</td>
      <td role="cell">Bergeside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Elisa</td>
      <td role="cell">McCullough</td>
      <td data-value="1164585600000" role="cell" class="epp-ar">2006-11-27</td>
      <td role="cell">Port Maurinestad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Opal</td>
      <td role="cell">Jacobs</td>
      <td data-value="-1448668800000" role="cell" class="epp-ar">1924-02-05</td>
      <td role="cell">Hilpertmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Jayda</td>
      <td role="cell">Hilll</td>
      <td data-value="-1729987200000" role="cell" class="epp-ar">1915-03-08</td>
      <td role="cell">Lake Elijahtown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Lola</td>
      <td role="cell">Brown</td>
      <td data-value="1767744000000" role="cell" class="epp-ar">2026-01-07</td>
      <td role="cell">Predovicbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Luisa</td>
      <td role="cell">Hudson</td>
      <td data-value="-761270400000" role="cell" class="epp-ar">1945-11-17</td>
      <td role="cell">South Candido</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Dimitri</td>
      <td role="cell">Effertz</td>
      <td data-value="-1646956800000" role="cell" class="epp-ar">1917-10-24</td>
      <td role="cell">Gutmannland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Jarred</td>
      <td role="cell">Streich</td>
      <td data-value="-1008028800000" role="cell" class="epp-ar">1938-01-22</td>
      <td role="cell">New Meta</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Charley</td>
      <td role="cell">Bradtke</td>
      <td data-value="-1957737600000" role="cell" class="epp-ar">1907-12-19</td>
      <td role="cell">Armstrongtown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Chelsea</td>
      <td role="cell">O'Kon</td>
      <td data-value="204768000000" role="cell" class="epp-ar">1976-06-28</td>
      <td role="cell">Port Sadye</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Patience</td>
      <td role="cell">Hodkiewicz</td>
      <td data-value="-1156032000000" role="cell" class="epp-ar">1933-05-15</td>
      <td role="cell">Antwanhaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Elyse</td>
      <td role="cell">Purdy</td>
      <td data-value="345686400000" role="cell" class="epp-ar">1980-12-15</td>
      <td role="cell">Guidoshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Kirsten</td>
      <td role="cell">Hane</td>
      <td data-value="1667088000000" role="cell" class="epp-ar">2022-10-30</td>
      <td role="cell">Cormierburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Vincent</td>
      <td role="cell">Stiedemann</td>
      <td data-value="-1750464000000" role="cell" class="epp-ar">1914-07-14</td>
      <td role="cell">Port Liam</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Avery</td>
      <td role="cell">Price</td>
      <td data-value="-1860710400000" role="cell" class="epp-ar">1911-01-15</td>
      <td role="cell">Clintonborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Uriah</td>
      <td role="cell">Runolfsdottir</td>
      <td data-value="104630400000" role="cell" class="epp-ar">1973-04-26</td>
      <td role="cell">Turcotteborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Lucas</td>
      <td role="cell">Kirlin</td>
      <td data-value="1503100800000" role="cell" class="epp-ar">2017-08-19</td>
      <td role="cell">Prosaccoberg</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;
}