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 Barrett Abbott 1977-07-27 Hayesview
Scotland Waldo Marks 1915-07-13 Kautzerbury
England Kathryn Thompson 2006-03-19 Violetmouth
Scotland Oliver Schuster 1936-11-27 East Kristin
Scotland Norwood Conroy 1991-05-03 Cordellbury
England Caden Schaden 2018-01-10 Port Dayton
Northern Ireland Jillian Kuvalis 2008-04-12 Lake Adeline
Wales Lora Quitzon 1960-10-12 New Naomiton
Northern Ireland Eleonore Rempel 1923-12-15 New Margarethaven
Wales Johann Jerde 1994-05-04 East Coby
England Arne Goodwin 1914-12-07 Konopelskishire
Northern Ireland Dayton Kunze 1964-05-30 West Bell
Northern Ireland Simone Reinger 2005-08-28 East Willis
Scotland Iva Powlowski 1919-03-23 Douglasfurt
Northern Ireland Alvis Orn 2012-10-28 Dixietown
Northern Ireland Helga Grimes 2024-08-18 Stephonmouth
England Reta Swaniawski 1962-04-24 Thelmaton
Northern Ireland Horacio Schmeler 1996-05-29 Lake Ryley
England Waldo Mann 1971-04-03 South Nat
Northern Ireland Alejandra Blanda 2011-12-04 West Krystalton
Scotland Thad D'Amore 1942-10-25 Port Alexandrine
Wales Shanna McCullough 1932-12-14 Hamilltown
England Alexane Casper 1964-07-28 Libbiefurt
Northern Ireland Cortney Emmerich 1975-09-30 New Cheyenne
England June Brown 1928-05-22 South Kenya
Scotland Stefan Murphy 1991-02-03 Boyertown
England Tess Ernser 1970-08-29 Mrazland
Northern Ireland Nils Konopelski 1939-07-16 East Favian
Scotland Tevin Haag 1945-05-10 Port Joannefort
Scotland Asha Mueller 2015-10-20 North Gerry
Wales Nicolette Johnston 1965-03-23 Wolffberg
Wales Carolyne Sawayn 1997-08-21 East Cade
England Freeda Stiedemann 1916-08-10 Robelfort
Wales Fannie Considine 2006-05-04 North Margaretestad
Scotland Savanna Hettinger 1999-01-17 West Evie
Wales Abbigail Emard 1918-01-13 Trantowmouth
Scotland Erna Herman 1962-06-01 West Elizaton
England Adeline Wolff 1970-08-05 Port Watson
Scotland Winston Zboncak 1994-09-16 Lake Zack
Northern Ireland Braulio Leannon 1964-10-05 Port Doyle
Scotland Katlynn Hettinger 2001-03-17 Carytown
Scotland Letitia Mann 1936-05-26 West Madelynn
Northern Ireland Joel West 2007-09-12 New Percytown
Scotland Ken Boyle 1973-01-15 Cruickshankfort
Wales Marianne Barrows 2005-06-24 West Cortez
Scotland Olin Satterfield 1971-09-16 O'Connellville
England Judy Ortiz 2003-08-05 Pfefferville
England Giles Howell 2003-05-24 West Prudence
England Gustave Jacobson 1977-01-25 South Jackelineberg
England Beatrice Nolan 1909-08-23 South Hoyt

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">Barrett</td>
      <td role="cell">Abbott</td>
      <td data-value="238809600000" role="cell" class="epp-ar">1977-07-27</td>
      <td role="cell">Hayesview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Waldo</td>
      <td role="cell">Marks</td>
      <td data-value="-1719014400000" role="cell" class="epp-ar">1915-07-13</td>
      <td role="cell">Kautzerbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Kathryn</td>
      <td role="cell">Thompson</td>
      <td data-value="1142726400000" role="cell" class="epp-ar">2006-03-19</td>
      <td role="cell">Violetmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Oliver</td>
      <td role="cell">Schuster</td>
      <td data-value="-1044403200000" role="cell" class="epp-ar">1936-11-27</td>
      <td role="cell">East Kristin</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Norwood</td>
      <td role="cell">Conroy</td>
      <td data-value="673228800000" role="cell" class="epp-ar">1991-05-03</td>
      <td role="cell">Cordellbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Caden</td>
      <td role="cell">Schaden</td>
      <td data-value="1515542400000" role="cell" class="epp-ar">2018-01-10</td>
      <td role="cell">Port Dayton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jillian</td>
      <td role="cell">Kuvalis</td>
      <td data-value="1207958400000" role="cell" class="epp-ar">2008-04-12</td>
      <td role="cell">Lake Adeline</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Lora</td>
      <td role="cell">Quitzon</td>
      <td data-value="-290995200000" role="cell" class="epp-ar">1960-10-12</td>
      <td role="cell">New Naomiton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Eleonore</td>
      <td role="cell">Rempel</td>
      <td data-value="-1453161600000" role="cell" class="epp-ar">1923-12-15</td>
      <td role="cell">New Margarethaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Johann</td>
      <td role="cell">Jerde</td>
      <td data-value="768009600000" role="cell" class="epp-ar">1994-05-04</td>
      <td role="cell">East Coby</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Arne</td>
      <td role="cell">Goodwin</td>
      <td data-value="-1737849600000" role="cell" class="epp-ar">1914-12-07</td>
      <td role="cell">Konopelskishire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Dayton</td>
      <td role="cell">Kunze</td>
      <td data-value="-176428800000" role="cell" class="epp-ar">1964-05-30</td>
      <td role="cell">West Bell</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Simone</td>
      <td role="cell">Reinger</td>
      <td data-value="1125187200000" role="cell" class="epp-ar">2005-08-28</td>
      <td role="cell">East Willis</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Iva</td>
      <td role="cell">Powlowski</td>
      <td data-value="-1602460800000" role="cell" class="epp-ar">1919-03-23</td>
      <td role="cell">Douglasfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Alvis</td>
      <td role="cell">Orn</td>
      <td data-value="1351382400000" role="cell" class="epp-ar">2012-10-28</td>
      <td role="cell">Dixietown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Helga</td>
      <td role="cell">Grimes</td>
      <td data-value="1723939200000" role="cell" class="epp-ar">2024-08-18</td>
      <td role="cell">Stephonmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Reta</td>
      <td role="cell">Swaniawski</td>
      <td data-value="-242697600000" role="cell" class="epp-ar">1962-04-24</td>
      <td role="cell">Thelmaton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Horacio</td>
      <td role="cell">Schmeler</td>
      <td data-value="833328000000" role="cell" class="epp-ar">1996-05-29</td>
      <td role="cell">Lake Ryley</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Waldo</td>
      <td role="cell">Mann</td>
      <td data-value="39484800000" role="cell" class="epp-ar">1971-04-03</td>
      <td role="cell">South Nat</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Alejandra</td>
      <td role="cell">Blanda</td>
      <td data-value="1322956800000" role="cell" class="epp-ar">2011-12-04</td>
      <td role="cell">West Krystalton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Thad</td>
      <td role="cell">D'Amore</td>
      <td data-value="-857952000000" role="cell" class="epp-ar">1942-10-25</td>
      <td role="cell">Port Alexandrine</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Shanna</td>
      <td role="cell">McCullough</td>
      <td data-value="-1169164800000" role="cell" class="epp-ar">1932-12-14</td>
      <td role="cell">Hamilltown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Alexane</td>
      <td role="cell">Casper</td>
      <td data-value="-171331200000" role="cell" class="epp-ar">1964-07-28</td>
      <td role="cell">Libbiefurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Cortney</td>
      <td role="cell">Emmerich</td>
      <td data-value="181267200000" role="cell" class="epp-ar">1975-09-30</td>
      <td role="cell">New Cheyenne</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">June</td>
      <td role="cell">Brown</td>
      <td data-value="-1313193600000" role="cell" class="epp-ar">1928-05-22</td>
      <td role="cell">South Kenya</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Stefan</td>
      <td role="cell">Murphy</td>
      <td data-value="665539200000" role="cell" class="epp-ar">1991-02-03</td>
      <td role="cell">Boyertown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Tess</td>
      <td role="cell">Ernser</td>
      <td data-value="20736000000" role="cell" class="epp-ar">1970-08-29</td>
      <td role="cell">Mrazland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Nils</td>
      <td role="cell">Konopelski</td>
      <td data-value="-961372800000" role="cell" class="epp-ar">1939-07-16</td>
      <td role="cell">East Favian</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Tevin</td>
      <td role="cell">Haag</td>
      <td data-value="-777772800000" role="cell" class="epp-ar">1945-05-10</td>
      <td role="cell">Port Joannefort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Asha</td>
      <td role="cell">Mueller</td>
      <td data-value="1445299200000" role="cell" class="epp-ar">2015-10-20</td>
      <td role="cell">North Gerry</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Nicolette</td>
      <td role="cell">Johnston</td>
      <td data-value="-150768000000" role="cell" class="epp-ar">1965-03-23</td>
      <td role="cell">Wolffberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Carolyne</td>
      <td role="cell">Sawayn</td>
      <td data-value="872121600000" role="cell" class="epp-ar">1997-08-21</td>
      <td role="cell">East Cade</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Freeda</td>
      <td role="cell">Stiedemann</td>
      <td data-value="-1684972800000" role="cell" class="epp-ar">1916-08-10</td>
      <td role="cell">Robelfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Fannie</td>
      <td role="cell">Considine</td>
      <td data-value="1146700800000" role="cell" class="epp-ar">2006-05-04</td>
      <td role="cell">North Margaretestad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Savanna</td>
      <td role="cell">Hettinger</td>
      <td data-value="916531200000" role="cell" class="epp-ar">1999-01-17</td>
      <td role="cell">West Evie</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Abbigail</td>
      <td role="cell">Emard</td>
      <td data-value="-1639958400000" role="cell" class="epp-ar">1918-01-13</td>
      <td role="cell">Trantowmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Erna</td>
      <td role="cell">Herman</td>
      <td data-value="-239414400000" role="cell" class="epp-ar">1962-06-01</td>
      <td role="cell">West Elizaton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Adeline</td>
      <td role="cell">Wolff</td>
      <td data-value="18662400000" role="cell" class="epp-ar">1970-08-05</td>
      <td role="cell">Port Watson</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Winston</td>
      <td role="cell">Zboncak</td>
      <td data-value="779673600000" role="cell" class="epp-ar">1994-09-16</td>
      <td role="cell">Lake Zack</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Braulio</td>
      <td role="cell">Leannon</td>
      <td data-value="-165369600000" role="cell" class="epp-ar">1964-10-05</td>
      <td role="cell">Port Doyle</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Katlynn</td>
      <td role="cell">Hettinger</td>
      <td data-value="984787200000" role="cell" class="epp-ar">2001-03-17</td>
      <td role="cell">Carytown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Letitia</td>
      <td role="cell">Mann</td>
      <td data-value="-1060387200000" role="cell" class="epp-ar">1936-05-26</td>
      <td role="cell">West Madelynn</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Joel</td>
      <td role="cell">West</td>
      <td data-value="1189555200000" role="cell" class="epp-ar">2007-09-12</td>
      <td role="cell">New Percytown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Ken</td>
      <td role="cell">Boyle</td>
      <td data-value="95904000000" role="cell" class="epp-ar">1973-01-15</td>
      <td role="cell">Cruickshankfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Marianne</td>
      <td role="cell">Barrows</td>
      <td data-value="1119571200000" role="cell" class="epp-ar">2005-06-24</td>
      <td role="cell">West Cortez</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Olin</td>
      <td role="cell">Satterfield</td>
      <td data-value="53827200000" role="cell" class="epp-ar">1971-09-16</td>
      <td role="cell">O'Connellville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Judy</td>
      <td role="cell">Ortiz</td>
      <td data-value="1060041600000" role="cell" class="epp-ar">2003-08-05</td>
      <td role="cell">Pfefferville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Giles</td>
      <td role="cell">Howell</td>
      <td data-value="1053734400000" role="cell" class="epp-ar">2003-05-24</td>
      <td role="cell">West Prudence</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Gustave</td>
      <td role="cell">Jacobson</td>
      <td data-value="222998400000" role="cell" class="epp-ar">1977-01-25</td>
      <td role="cell">South Jackelineberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Beatrice</td>
      <td role="cell">Nolan</td>
      <td data-value="-1904774400000" role="cell" class="epp-ar">1909-08-23</td>
      <td role="cell">South Hoyt</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;
}