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 Rylee McCullough 2018-05-29 Hahnville
Northern Ireland Alicia Will 2016-03-25 Dietrichbury
Northern Ireland Dahlia Jacobs 1952-12-30 Lake Ardithchester
Wales Katrina Greenholt 1964-09-05 Timothyfurt
Scotland Casimir Feeney 1979-12-19 South Adonisshire
Wales Casandra Kreiger 1971-03-03 Muellerchester
Scotland Deion Leuschke 1969-03-10 Bayerberg
England Hallie Kunze 1967-08-04 Lake Aisha
England Lenora Schowalter 1952-07-20 Tristonchester
Wales Virginie Feeney 1948-03-21 North Abraham
Wales Eino Veum 1926-02-28 South Kiel
Wales Brooklyn Lockman 2002-04-03 New Birdieborough
England Johnathon Schinner 1923-04-28 Aliciamouth
Wales Columbus Mayer 1999-10-31 South Jalon
Northern Ireland Kallie Ziemann 2017-04-28 Kerlukeborough
Northern Ireland Destini Smith 2002-10-18 Port Dortha
Wales Griffin Bayer 2015-09-29 Andrewport
England Durward Nienow 1934-06-29 Kristianfort
Scotland Miguel Yundt 2024-10-04 Robintown
Wales Jaylon Yost 1942-01-30 East Camila
Northern Ireland Janie Baumbach 1908-06-13 South Kadenfort
Scotland Fannie Botsford 1953-04-10 South Clairview
Scotland Johan Hahn 1949-01-26 Antonettaberg
Northern Ireland Terrance Kshlerin 1996-10-27 Mathildeport
Wales Maye Hyatt 1999-12-17 East Greysonshire
Scotland Delia Wintheiser 2011-01-02 Serenafort
Wales Donnell Schowalter 1950-01-01 Brionnahaven
Scotland Serenity Rempel 1943-09-28 Pattiemouth
Northern Ireland Duane Smitham 1951-04-02 Casperhaven
Wales Anjali Spencer 2016-04-16 Lake Alex
Scotland Marlene Powlowski 1964-12-21 Hoegerstad
Scotland Nyasia Kerluke 1952-05-22 West Derickville
Northern Ireland Jazmin Erdman 1972-09-18 Wunschtown
Scotland Orland Ernser 1925-01-14 Kaiafurt
Northern Ireland Mekhi Brekke 1926-06-06 Eugenetown
Northern Ireland Andreanne Borer 2014-02-27 Kadenfurt
Northern Ireland Jamil Keebler 1946-02-12 Davinborough
Scotland Celine Cummings 1980-06-01 New Felipa
Scotland Elroy Watsica 1998-05-22 North Jarodland
England Lera Kiehn 1985-12-03 Port Stephany
Northern Ireland Steve Cummings 1926-07-26 Camilleshire
Scotland Eden Anderson 2014-09-12 New Eda
England Kenton Keeling 2009-10-07 Simonisfurt
England Luella Reilly 1982-04-08 East Marlen
England Tyshawn Koss 1964-12-17 West Tremaine
Scotland Quincy Jast 1955-05-15 North Alta
England Kody Haley 2012-02-12 Port Jamilburgh
Wales Mozell Schaefer 2006-02-13 Haleyburgh
Scotland Boyd Russel 1972-09-13 Raumouth
Northern Ireland Willy Roberts 1978-02-19 West Stefan

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">Rylee</td>
      <td role="cell">McCullough</td>
      <td data-value="1527552000000" role="cell" class="epp-ar epp-s1">2018-05-29</td>
      <td role="cell">Hahnville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Alicia</td>
      <td role="cell">Will</td>
      <td data-value="1458864000000" role="cell" class="epp-ar epp-s1">2016-03-25</td>
      <td role="cell">Dietrichbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Dahlia</td>
      <td role="cell">Jacobs</td>
      <td data-value="-536630400000" role="cell" class="epp-ar epp-s1">1952-12-30</td>
      <td role="cell">Lake Ardithchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Katrina</td>
      <td role="cell">Greenholt</td>
      <td data-value="-167961600000" role="cell" class="epp-ar epp-s1">1964-09-05</td>
      <td role="cell">Timothyfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Casimir</td>
      <td role="cell">Feeney</td>
      <td data-value="314409600000" role="cell" class="epp-ar epp-s1">1979-12-19</td>
      <td role="cell">South Adonisshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Casandra</td>
      <td role="cell">Kreiger</td>
      <td data-value="36806400000" role="cell" class="epp-ar epp-s1">1971-03-03</td>
      <td role="cell">Muellerchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Deion</td>
      <td role="cell">Leuschke</td>
      <td data-value="-25660800000" role="cell" class="epp-ar epp-s1">1969-03-10</td>
      <td role="cell">Bayerberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Hallie</td>
      <td role="cell">Kunze</td>
      <td data-value="-76118400000" role="cell" class="epp-ar epp-s1">1967-08-04</td>
      <td role="cell">Lake Aisha</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Lenora</td>
      <td role="cell">Schowalter</td>
      <td data-value="-550713600000" role="cell" class="epp-ar epp-s1">1952-07-20</td>
      <td role="cell">Tristonchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Virginie</td>
      <td role="cell">Feeney</td>
      <td data-value="-687398400000" role="cell" class="epp-ar epp-s1">1948-03-21</td>
      <td role="cell">North Abraham</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Eino</td>
      <td role="cell">Veum</td>
      <td data-value="-1383523200000" role="cell" class="epp-ar epp-s1">1926-02-28</td>
      <td role="cell">South Kiel</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Brooklyn</td>
      <td role="cell">Lockman</td>
      <td data-value="1017792000000" role="cell" class="epp-ar epp-s1">2002-04-03</td>
      <td role="cell">New Birdieborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Johnathon</td>
      <td role="cell">Schinner</td>
      <td data-value="-1473120000000" role="cell" class="epp-ar epp-s1">1923-04-28</td>
      <td role="cell">Aliciamouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Columbus</td>
      <td role="cell">Mayer</td>
      <td data-value="941328000000" role="cell" class="epp-ar epp-s1">1999-10-31</td>
      <td role="cell">South Jalon</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Kallie</td>
      <td role="cell">Ziemann</td>
      <td data-value="1493337600000" role="cell" class="epp-ar epp-s1">2017-04-28</td>
      <td role="cell">Kerlukeborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Destini</td>
      <td role="cell">Smith</td>
      <td data-value="1034899200000" role="cell" class="epp-ar epp-s1">2002-10-18</td>
      <td role="cell">Port Dortha</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Griffin</td>
      <td role="cell">Bayer</td>
      <td data-value="1443484800000" role="cell" class="epp-ar epp-s1">2015-09-29</td>
      <td role="cell">Andrewport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Durward</td>
      <td role="cell">Nienow</td>
      <td data-value="-1120608000000" role="cell" class="epp-ar epp-s1">1934-06-29</td>
      <td role="cell">Kristianfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Miguel</td>
      <td role="cell">Yundt</td>
      <td data-value="1728000000000" role="cell" class="epp-ar epp-s1">2024-10-04</td>
      <td role="cell">Robintown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Jaylon</td>
      <td role="cell">Yost</td>
      <td data-value="-881107200000" role="cell" class="epp-ar epp-s1">1942-01-30</td>
      <td role="cell">East Camila</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Janie</td>
      <td role="cell">Baumbach</td>
      <td data-value="-1942444800000" role="cell" class="epp-ar epp-s1">1908-06-13</td>
      <td role="cell">South Kadenfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Fannie</td>
      <td role="cell">Botsford</td>
      <td data-value="-527904000000" role="cell" class="epp-ar epp-s1">1953-04-10</td>
      <td role="cell">South Clairview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Johan</td>
      <td role="cell">Hahn</td>
      <td data-value="-660528000000" role="cell" class="epp-ar epp-s1">1949-01-26</td>
      <td role="cell">Antonettaberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Terrance</td>
      <td role="cell">Kshlerin</td>
      <td data-value="846374400000" role="cell" class="epp-ar epp-s1">1996-10-27</td>
      <td role="cell">Mathildeport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Maye</td>
      <td role="cell">Hyatt</td>
      <td data-value="945388800000" role="cell" class="epp-ar epp-s1">1999-12-17</td>
      <td role="cell">East Greysonshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Delia</td>
      <td role="cell">Wintheiser</td>
      <td data-value="1293926400000" role="cell" class="epp-ar epp-s1">2011-01-02</td>
      <td role="cell">Serenafort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Donnell</td>
      <td role="cell">Schowalter</td>
      <td data-value="-631152000000" role="cell" class="epp-ar epp-s1">1950-01-01</td>
      <td role="cell">Brionnahaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Serenity</td>
      <td role="cell">Rempel</td>
      <td data-value="-828748800000" role="cell" class="epp-ar epp-s1">1943-09-28</td>
      <td role="cell">Pattiemouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Duane</td>
      <td role="cell">Smitham</td>
      <td data-value="-591753600000" role="cell" class="epp-ar epp-s1">1951-04-02</td>
      <td role="cell">Casperhaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Anjali</td>
      <td role="cell">Spencer</td>
      <td data-value="1460764800000" role="cell" class="epp-ar epp-s1">2016-04-16</td>
      <td role="cell">Lake Alex</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Marlene</td>
      <td role="cell">Powlowski</td>
      <td data-value="-158716800000" role="cell" class="epp-ar epp-s1">1964-12-21</td>
      <td role="cell">Hoegerstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Nyasia</td>
      <td role="cell">Kerluke</td>
      <td data-value="-555811200000" role="cell" class="epp-ar epp-s1">1952-05-22</td>
      <td role="cell">West Derickville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jazmin</td>
      <td role="cell">Erdman</td>
      <td data-value="85622400000" role="cell" class="epp-ar epp-s1">1972-09-18</td>
      <td role="cell">Wunschtown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Orland</td>
      <td role="cell">Ernser</td>
      <td data-value="-1418947200000" role="cell" class="epp-ar epp-s1">1925-01-14</td>
      <td role="cell">Kaiafurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Mekhi</td>
      <td role="cell">Brekke</td>
      <td data-value="-1375056000000" role="cell" class="epp-ar epp-s1">1926-06-06</td>
      <td role="cell">Eugenetown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Andreanne</td>
      <td role="cell">Borer</td>
      <td data-value="1393459200000" role="cell" class="epp-ar epp-s1">2014-02-27</td>
      <td role="cell">Kadenfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jamil</td>
      <td role="cell">Keebler</td>
      <td data-value="-753753600000" role="cell" class="epp-ar epp-s1">1946-02-12</td>
      <td role="cell">Davinborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Celine</td>
      <td role="cell">Cummings</td>
      <td data-value="328665600000" role="cell" class="epp-ar epp-s1">1980-06-01</td>
      <td role="cell">New Felipa</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Elroy</td>
      <td role="cell">Watsica</td>
      <td data-value="895795200000" role="cell" class="epp-ar epp-s1">1998-05-22</td>
      <td role="cell">North Jarodland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Lera</td>
      <td role="cell">Kiehn</td>
      <td data-value="502416000000" role="cell" class="epp-ar epp-s1">1985-12-03</td>
      <td role="cell">Port Stephany</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Steve</td>
      <td role="cell">Cummings</td>
      <td data-value="-1370736000000" role="cell" class="epp-ar epp-s1">1926-07-26</td>
      <td role="cell">Camilleshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Eden</td>
      <td role="cell">Anderson</td>
      <td data-value="1410480000000" role="cell" class="epp-ar epp-s1">2014-09-12</td>
      <td role="cell">New Eda</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Kenton</td>
      <td role="cell">Keeling</td>
      <td data-value="1254873600000" role="cell" class="epp-ar epp-s1">2009-10-07</td>
      <td role="cell">Simonisfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Luella</td>
      <td role="cell">Reilly</td>
      <td data-value="387072000000" role="cell" class="epp-ar epp-s1">1982-04-08</td>
      <td role="cell">East Marlen</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Tyshawn</td>
      <td role="cell">Koss</td>
      <td data-value="-159062400000" role="cell" class="epp-ar epp-s1">1964-12-17</td>
      <td role="cell">West Tremaine</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Quincy</td>
      <td role="cell">Jast</td>
      <td data-value="-461808000000" role="cell" class="epp-ar epp-s1">1955-05-15</td>
      <td role="cell">North Alta</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Kody</td>
      <td role="cell">Haley</td>
      <td data-value="1329004800000" role="cell" class="epp-ar epp-s1">2012-02-12</td>
      <td role="cell">Port Jamilburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Mozell</td>
      <td role="cell">Schaefer</td>
      <td data-value="1139788800000" role="cell" class="epp-ar epp-s1">2006-02-13</td>
      <td role="cell">Haleyburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Boyd</td>
      <td role="cell">Russel</td>
      <td data-value="85190400000" role="cell" class="epp-ar epp-s1">1972-09-13</td>
      <td role="cell">Raumouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Willy</td>
      <td role="cell">Roberts</td>
      <td data-value="256694400000" role="cell" class="epp-ar epp-s1">1978-02-19</td>
      <td role="cell">West Stefan</td>
    </tr>
  </tbody>
</table>
            
        

EPPlus converts the table styling in Excel to a separate stylesheet.

        
 table.epplus-table{
  font-family:Aptos Narrow;
  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;
}
.epp-s1{
  white-space: nowrap;
  vertical-align:bottom;
}