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 Penelope Hackett 1958-02-22 Port Cortneyburgh
Northern Ireland Mayra Harris 1940-03-05 Laurianefurt
Scotland Dell Paucek 1968-03-02 Quitzonbury
England April Turner 2008-03-11 Lake Amya
Northern Ireland Tessie Schmeler 2015-01-14 South Wilfred
England Freda Monahan 1978-01-29 Treyberg
Northern Ireland Davin Brakus 1923-09-12 New Coleport
England Rhoda Senger 1997-07-04 North Sydniville
Scotland Dovie Wisozk 1909-03-29 Haleybury
England Rod Hudson 1954-05-23 Hayleeside
Northern Ireland Madelyn Flatley 1965-04-13 Lake Leora
Northern Ireland Nola Jones 1956-09-26 South Taylorview
Wales Mariah Konopelski 1964-07-03 Port Fernchester
England Reggie Smith 1973-05-30 Rempelville
Northern Ireland Clifford Sawayn 1942-05-26 East Murrayton
Northern Ireland Van Nikolaus 1994-02-18 West Daniellafort
Wales Kenny Cummings 1909-10-03 North Gildabury
Wales Verla Maggio 1956-01-26 North Jessikabury
Wales Keagan Langworth 1960-07-19 North Robertfort
England Orpha Farrell 1922-08-28 Titoville
Scotland Janick Boyle 1965-04-03 Port Issac
Scotland Eugenia Greenholt 2021-10-22 South Rosemaryport
Wales Sterling Stehr 1979-11-24 Lowellland
Northern Ireland Katelyn Krajcik 2000-07-28 Orvillechester
Wales Erica Powlowski 1963-07-06 Genevievefurt
Wales Melvina Bergnaum 1939-08-16 South Malachiberg
Wales Stephan Muller 1972-04-08 Claireville
Wales Enos Rippin 1982-04-29 Lake Eulahburgh
Northern Ireland Lorenza Kulas 1959-11-18 Lake Alexys
England Haleigh Osinski 1952-08-11 Ebertmouth
England Alycia Conn 2003-01-29 Port Bailey
Scotland Ashton Jacobson 1954-03-01 New Kraig
Northern Ireland Otilia Yundt 2003-05-23 Donnellystad
Northern Ireland May Ebert 1980-05-31 Strosinmouth
Wales Julian Cummings 1965-01-18 Lake Dallasmouth
Wales Hazel Heidenreich 2009-04-19 East Griffinton
England Missouri Murphy 1941-11-17 Carmelview
England Jayson Feil 1953-12-08 Hicklemouth
Wales Colby Morar 1985-08-06 Volkmanberg
Wales Johnny Hammes 1988-10-19 Priscillaland
Northern Ireland Graciela Wolf 1974-04-14 Kennethtown
Scotland Arlene Pfannerstill 2015-06-09 Conradfort
Northern Ireland Eloisa Wiegand 1965-01-23 Nienowfort
Wales Edwina Reinger 1967-10-01 Port Jed
Wales Madisen Wehner 2016-03-19 New Danteville
England Aaliyah Hauck 2006-12-01 South Hassanland
Northern Ireland Zetta Lynch 1952-11-06 Zulachester
Wales Shannon Murphy 2013-06-04 Lake Nehaville
Wales Javier Parisian 1965-03-19 Cathymouth
Scotland Moshe O'Connell 1975-12-08 Hipolitofurt

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">Penelope</td>
      <td role="cell">Hackett</td>
      <td data-value="-374198400000" role="cell" class="epp-ar">1958-02-22</td>
      <td role="cell">Port Cortneyburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Mayra</td>
      <td role="cell">Harris</td>
      <td data-value="-941241600000" role="cell" class="epp-ar">1940-03-05</td>
      <td role="cell">Laurianefurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Dell</td>
      <td role="cell">Paucek</td>
      <td data-value="-57888000000" role="cell" class="epp-ar">1968-03-02</td>
      <td role="cell">Quitzonbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">April</td>
      <td role="cell">Turner</td>
      <td data-value="1205193600000" role="cell" class="epp-ar">2008-03-11</td>
      <td role="cell">Lake Amya</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Tessie</td>
      <td role="cell">Schmeler</td>
      <td data-value="1421193600000" role="cell" class="epp-ar">2015-01-14</td>
      <td role="cell">South Wilfred</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Freda</td>
      <td role="cell">Monahan</td>
      <td data-value="254880000000" role="cell" class="epp-ar">1978-01-29</td>
      <td role="cell">Treyberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Davin</td>
      <td role="cell">Brakus</td>
      <td data-value="-1461283200000" role="cell" class="epp-ar">1923-09-12</td>
      <td role="cell">New Coleport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Rhoda</td>
      <td role="cell">Senger</td>
      <td data-value="867974400000" role="cell" class="epp-ar">1997-07-04</td>
      <td role="cell">North Sydniville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Dovie</td>
      <td role="cell">Wisozk</td>
      <td data-value="-1917475200000" role="cell" class="epp-ar">1909-03-29</td>
      <td role="cell">Haleybury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Rod</td>
      <td role="cell">Hudson</td>
      <td data-value="-492652800000" role="cell" class="epp-ar">1954-05-23</td>
      <td role="cell">Hayleeside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Madelyn</td>
      <td role="cell">Flatley</td>
      <td data-value="-148953600000" role="cell" class="epp-ar">1965-04-13</td>
      <td role="cell">Lake Leora</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Nola</td>
      <td role="cell">Jones</td>
      <td data-value="-418608000000" role="cell" class="epp-ar">1956-09-26</td>
      <td role="cell">South Taylorview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Mariah</td>
      <td role="cell">Konopelski</td>
      <td data-value="-173491200000" role="cell" class="epp-ar">1964-07-03</td>
      <td role="cell">Port Fernchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Reggie</td>
      <td role="cell">Smith</td>
      <td data-value="107568000000" role="cell" class="epp-ar">1973-05-30</td>
      <td role="cell">Rempelville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Clifford</td>
      <td role="cell">Sawayn</td>
      <td data-value="-871084800000" role="cell" class="epp-ar">1942-05-26</td>
      <td role="cell">East Murrayton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Van</td>
      <td role="cell">Nikolaus</td>
      <td data-value="761529600000" role="cell" class="epp-ar">1994-02-18</td>
      <td role="cell">West Daniellafort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Kenny</td>
      <td role="cell">Cummings</td>
      <td data-value="-1901232000000" role="cell" class="epp-ar">1909-10-03</td>
      <td role="cell">North Gildabury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Verla</td>
      <td role="cell">Maggio</td>
      <td data-value="-439689600000" role="cell" class="epp-ar">1956-01-26</td>
      <td role="cell">North Jessikabury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Keagan</td>
      <td role="cell">Langworth</td>
      <td data-value="-298339200000" role="cell" class="epp-ar">1960-07-19</td>
      <td role="cell">North Robertfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Orpha</td>
      <td role="cell">Farrell</td>
      <td data-value="-1494115200000" role="cell" class="epp-ar">1922-08-28</td>
      <td role="cell">Titoville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Janick</td>
      <td role="cell">Boyle</td>
      <td data-value="-149817600000" role="cell" class="epp-ar">1965-04-03</td>
      <td role="cell">Port Issac</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Eugenia</td>
      <td role="cell">Greenholt</td>
      <td data-value="1634860800000" role="cell" class="epp-ar">2021-10-22</td>
      <td role="cell">South Rosemaryport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Sterling</td>
      <td role="cell">Stehr</td>
      <td data-value="312249600000" role="cell" class="epp-ar">1979-11-24</td>
      <td role="cell">Lowellland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Katelyn</td>
      <td role="cell">Krajcik</td>
      <td data-value="964742400000" role="cell" class="epp-ar">2000-07-28</td>
      <td role="cell">Orvillechester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Erica</td>
      <td role="cell">Powlowski</td>
      <td data-value="-204854400000" role="cell" class="epp-ar">1963-07-06</td>
      <td role="cell">Genevievefurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Melvina</td>
      <td role="cell">Bergnaum</td>
      <td data-value="-958694400000" role="cell" class="epp-ar">1939-08-16</td>
      <td role="cell">South Malachiberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Stephan</td>
      <td role="cell">Muller</td>
      <td data-value="71539200000" role="cell" class="epp-ar">1972-04-08</td>
      <td role="cell">Claireville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Enos</td>
      <td role="cell">Rippin</td>
      <td data-value="388886400000" role="cell" class="epp-ar">1982-04-29</td>
      <td role="cell">Lake Eulahburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Lorenza</td>
      <td role="cell">Kulas</td>
      <td data-value="-319420800000" role="cell" class="epp-ar">1959-11-18</td>
      <td role="cell">Lake Alexys</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Haleigh</td>
      <td role="cell">Osinski</td>
      <td data-value="-548812800000" role="cell" class="epp-ar">1952-08-11</td>
      <td role="cell">Ebertmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Alycia</td>
      <td role="cell">Conn</td>
      <td data-value="1043798400000" role="cell" class="epp-ar">2003-01-29</td>
      <td role="cell">Port Bailey</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Ashton</td>
      <td role="cell">Jacobson</td>
      <td data-value="-499824000000" role="cell" class="epp-ar">1954-03-01</td>
      <td role="cell">New Kraig</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Otilia</td>
      <td role="cell">Yundt</td>
      <td data-value="1053648000000" role="cell" class="epp-ar">2003-05-23</td>
      <td role="cell">Donnellystad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">May</td>
      <td role="cell">Ebert</td>
      <td data-value="328579200000" role="cell" class="epp-ar">1980-05-31</td>
      <td role="cell">Strosinmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Julian</td>
      <td role="cell">Cummings</td>
      <td data-value="-156297600000" role="cell" class="epp-ar">1965-01-18</td>
      <td role="cell">Lake Dallasmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Hazel</td>
      <td role="cell">Heidenreich</td>
      <td data-value="1240099200000" role="cell" class="epp-ar">2009-04-19</td>
      <td role="cell">East Griffinton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Missouri</td>
      <td role="cell">Murphy</td>
      <td data-value="-887500800000" role="cell" class="epp-ar">1941-11-17</td>
      <td role="cell">Carmelview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Jayson</td>
      <td role="cell">Feil</td>
      <td data-value="-506995200000" role="cell" class="epp-ar">1953-12-08</td>
      <td role="cell">Hicklemouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Colby</td>
      <td role="cell">Morar</td>
      <td data-value="492134400000" role="cell" class="epp-ar">1985-08-06</td>
      <td role="cell">Volkmanberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Johnny</td>
      <td role="cell">Hammes</td>
      <td data-value="593222400000" role="cell" class="epp-ar">1988-10-19</td>
      <td role="cell">Priscillaland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Graciela</td>
      <td role="cell">Wolf</td>
      <td data-value="135129600000" role="cell" class="epp-ar">1974-04-14</td>
      <td role="cell">Kennethtown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Arlene</td>
      <td role="cell">Pfannerstill</td>
      <td data-value="1433808000000" role="cell" class="epp-ar">2015-06-09</td>
      <td role="cell">Conradfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Eloisa</td>
      <td role="cell">Wiegand</td>
      <td data-value="-155865600000" role="cell" class="epp-ar">1965-01-23</td>
      <td role="cell">Nienowfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Edwina</td>
      <td role="cell">Reinger</td>
      <td data-value="-71107200000" role="cell" class="epp-ar">1967-10-01</td>
      <td role="cell">Port Jed</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Madisen</td>
      <td role="cell">Wehner</td>
      <td data-value="1458345600000" role="cell" class="epp-ar">2016-03-19</td>
      <td role="cell">New Danteville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Aaliyah</td>
      <td role="cell">Hauck</td>
      <td data-value="1164931200000" role="cell" class="epp-ar">2006-12-01</td>
      <td role="cell">South Hassanland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Zetta</td>
      <td role="cell">Lynch</td>
      <td data-value="-541296000000" role="cell" class="epp-ar">1952-11-06</td>
      <td role="cell">Zulachester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Shannon</td>
      <td role="cell">Murphy</td>
      <td data-value="1370304000000" role="cell" class="epp-ar">2013-06-04</td>
      <td role="cell">Lake Nehaville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Javier</td>
      <td role="cell">Parisian</td>
      <td data-value="-151113600000" role="cell" class="epp-ar">1965-03-19</td>
      <td role="cell">Cathymouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Moshe</td>
      <td role="cell">O'Connell</td>
      <td data-value="187228800000" role="cell" class="epp-ar">1975-12-08</td>
      <td role="cell">Hipolitofurt</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;
}