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
Northern Ireland Christy Weimann 2001-07-14 New Pinkfort
England Keara Douglas 1959-09-03 North Bertha
Northern Ireland Stone Kulas 2016-08-23 Bergechester
Northern Ireland Madisen Adams 2001-11-13 Russelside
England Alivia Mosciski 1974-09-17 Wernerton
Northern Ireland Jay Swaniawski 2010-09-01 Eichmanntown
Wales Muriel Hammes 1974-01-17 Lake Wilmamouth
Scotland Marcos Wyman 1939-04-06 South Arelymouth
Scotland Clair Vandervort 1962-11-28 Emersonstad
England Kailyn Roberts 1949-09-04 South Filomena
England Madge O'Reilly 1988-06-20 East Pollyside
England Linda Gusikowski 1969-10-11 Farrellfurt
Scotland Ebony Hoeger 1945-11-25 West Elinoreview
Wales Austin Farrell 1946-02-10 Jonatanland
England Demetrius Hagenes 2012-10-05 Dasiafort
England Norberto Murphy 1972-06-11 Veldatown
Northern Ireland Estel Lind 1963-07-05 Magdalenview
Scotland Joshua McLaughlin 2016-06-16 Gulgowskiview
England Susie Grady 1966-09-11 North Vernonside
Wales Yadira Kessler 1923-11-25 East Consuelo
Northern Ireland Buddy Nienow 1940-02-24 Jakobberg
Wales Cicero Quitzon 1934-04-15 East Juliana
Wales Aliza Vandervort 1981-05-08 New Retaview
Scotland Orrin Stokes 2011-09-15 Venafort
Scotland Tania Kuhlman 1998-05-31 Lake Millieton
Northern Ireland Stevie Lehner 2014-10-14 Hortensechester
Scotland Philip Purdy 1982-10-01 Lake Heather
England Bailee Hamill 1902-11-17 Janessashire
England Werner Johnson 1976-07-17 Russellshire
Scotland Laisha Stamm 1902-12-11 South Joyside
Wales Vicenta Rempel 1935-06-15 Lake Herman
Northern Ireland Angelica Torp 1975-11-27 South Dejonmouth
England Matilde McClure 1923-09-17 East Svenview
Northern Ireland Julie Runolfsdottir 1963-04-09 Lake Nya
Northern Ireland Bradley Metz 1947-07-27 VonRuedenland
England Ansel Corkery 2011-08-01 Bednarchester
Scotland Lenora Schamberger 2014-08-01 Deontaeview
Wales Rebecca Gerhold 2024-03-11 South Kacie
Wales Noble Hickle 1984-02-26 Runolfssonfort
Wales Montana Deckow 1963-09-11 North Laishahaven
Wales Dorris Lindgren 1966-12-09 Abshireton
Northern Ireland Lina Hahn 2005-01-04 Quitzonport
Wales Donnie Rolfson 2006-05-28 Nellaville
England Alexandra Gerhold 1989-08-03 East Clevelandmouth
Northern Ireland Mack D'Amore 1991-09-03 Ebonyfort
Scotland Trace Raynor 2016-04-15 Hilperttown
England Shany Luettgen 1984-06-04 East Madisenchester
Scotland Audreanne D'Amore 1962-12-31 East Lilianemouth
Wales Tobin Dibbert 1907-01-16 Littleshire
Scotland Logan Beer 2017-07-24 South Jesshaven

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">Northern Ireland</td>
      <td role="cell">Christy</td>
      <td role="cell">Weimann</td>
      <td data-value="995068800000" role="cell" class="epp-ar">2001-07-14</td>
      <td role="cell">New Pinkfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Keara</td>
      <td role="cell">Douglas</td>
      <td data-value="-325987200000" role="cell" class="epp-ar">1959-09-03</td>
      <td role="cell">North Bertha</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Stone</td>
      <td role="cell">Kulas</td>
      <td data-value="1471910400000" role="cell" class="epp-ar">2016-08-23</td>
      <td role="cell">Bergechester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Madisen</td>
      <td role="cell">Adams</td>
      <td data-value="1005609600000" role="cell" class="epp-ar">2001-11-13</td>
      <td role="cell">Russelside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Alivia</td>
      <td role="cell">Mosciski</td>
      <td data-value="148608000000" role="cell" class="epp-ar">1974-09-17</td>
      <td role="cell">Wernerton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jay</td>
      <td role="cell">Swaniawski</td>
      <td data-value="1283299200000" role="cell" class="epp-ar">2010-09-01</td>
      <td role="cell">Eichmanntown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Muriel</td>
      <td role="cell">Hammes</td>
      <td data-value="127612800000" role="cell" class="epp-ar">1974-01-17</td>
      <td role="cell">Lake Wilmamouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Marcos</td>
      <td role="cell">Wyman</td>
      <td data-value="-970099200000" role="cell" class="epp-ar">1939-04-06</td>
      <td role="cell">South Arelymouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Clair</td>
      <td role="cell">Vandervort</td>
      <td data-value="-223862400000" role="cell" class="epp-ar">1962-11-28</td>
      <td role="cell">Emersonstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Kailyn</td>
      <td role="cell">Roberts</td>
      <td data-value="-641433600000" role="cell" class="epp-ar">1949-09-04</td>
      <td role="cell">South Filomena</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Madge</td>
      <td role="cell">O'Reilly</td>
      <td data-value="582768000000" role="cell" class="epp-ar">1988-06-20</td>
      <td role="cell">East Pollyside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Linda</td>
      <td role="cell">Gusikowski</td>
      <td data-value="-7084800000" role="cell" class="epp-ar">1969-10-11</td>
      <td role="cell">Farrellfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Ebony</td>
      <td role="cell">Hoeger</td>
      <td data-value="-760579200000" role="cell" class="epp-ar">1945-11-25</td>
      <td role="cell">West Elinoreview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Austin</td>
      <td role="cell">Farrell</td>
      <td data-value="-753926400000" role="cell" class="epp-ar">1946-02-10</td>
      <td role="cell">Jonatanland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Demetrius</td>
      <td role="cell">Hagenes</td>
      <td data-value="1349395200000" role="cell" class="epp-ar">2012-10-05</td>
      <td role="cell">Dasiafort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Norberto</td>
      <td role="cell">Murphy</td>
      <td data-value="77068800000" role="cell" class="epp-ar">1972-06-11</td>
      <td role="cell">Veldatown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Estel</td>
      <td role="cell">Lind</td>
      <td data-value="-204940800000" role="cell" class="epp-ar">1963-07-05</td>
      <td role="cell">Magdalenview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Joshua</td>
      <td role="cell">McLaughlin</td>
      <td data-value="1466035200000" role="cell" class="epp-ar">2016-06-16</td>
      <td role="cell">Gulgowskiview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Susie</td>
      <td role="cell">Grady</td>
      <td data-value="-104371200000" role="cell" class="epp-ar">1966-09-11</td>
      <td role="cell">North Vernonside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Yadira</td>
      <td role="cell">Kessler</td>
      <td data-value="-1454889600000" role="cell" class="epp-ar">1923-11-25</td>
      <td role="cell">East Consuelo</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Buddy</td>
      <td role="cell">Nienow</td>
      <td data-value="-942105600000" role="cell" class="epp-ar">1940-02-24</td>
      <td role="cell">Jakobberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Cicero</td>
      <td role="cell">Quitzon</td>
      <td data-value="-1127088000000" role="cell" class="epp-ar">1934-04-15</td>
      <td role="cell">East Juliana</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Aliza</td>
      <td role="cell">Vandervort</td>
      <td data-value="358128000000" role="cell" class="epp-ar">1981-05-08</td>
      <td role="cell">New Retaview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Orrin</td>
      <td role="cell">Stokes</td>
      <td data-value="1316044800000" role="cell" class="epp-ar">2011-09-15</td>
      <td role="cell">Venafort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Tania</td>
      <td role="cell">Kuhlman</td>
      <td data-value="896572800000" role="cell" class="epp-ar">1998-05-31</td>
      <td role="cell">Lake Millieton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Stevie</td>
      <td role="cell">Lehner</td>
      <td data-value="1413244800000" role="cell" class="epp-ar">2014-10-14</td>
      <td role="cell">Hortensechester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Philip</td>
      <td role="cell">Purdy</td>
      <td data-value="402278400000" role="cell" class="epp-ar">1982-10-01</td>
      <td role="cell">Lake Heather</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Bailee</td>
      <td role="cell">Hamill</td>
      <td data-value="-2118268800000" role="cell" class="epp-ar">1902-11-17</td>
      <td role="cell">Janessashire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Werner</td>
      <td role="cell">Johnson</td>
      <td data-value="206409600000" role="cell" class="epp-ar">1976-07-17</td>
      <td role="cell">Russellshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Laisha</td>
      <td role="cell">Stamm</td>
      <td data-value="-2116195200000" role="cell" class="epp-ar">1902-12-11</td>
      <td role="cell">South Joyside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Vicenta</td>
      <td role="cell">Rempel</td>
      <td data-value="-1090281600000" role="cell" class="epp-ar">1935-06-15</td>
      <td role="cell">Lake Herman</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Angelica</td>
      <td role="cell">Torp</td>
      <td data-value="186278400000" role="cell" class="epp-ar">1975-11-27</td>
      <td role="cell">South Dejonmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Matilde</td>
      <td role="cell">McClure</td>
      <td data-value="-1460851200000" role="cell" class="epp-ar">1923-09-17</td>
      <td role="cell">East Svenview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Julie</td>
      <td role="cell">Runolfsdottir</td>
      <td data-value="-212457600000" role="cell" class="epp-ar">1963-04-09</td>
      <td role="cell">Lake Nya</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Bradley</td>
      <td role="cell">Metz</td>
      <td data-value="-707961600000" role="cell" class="epp-ar">1947-07-27</td>
      <td role="cell">VonRuedenland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Ansel</td>
      <td role="cell">Corkery</td>
      <td data-value="1312156800000" role="cell" class="epp-ar">2011-08-01</td>
      <td role="cell">Bednarchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Lenora</td>
      <td role="cell">Schamberger</td>
      <td data-value="1406851200000" role="cell" class="epp-ar">2014-08-01</td>
      <td role="cell">Deontaeview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Rebecca</td>
      <td role="cell">Gerhold</td>
      <td data-value="1710115200000" role="cell" class="epp-ar">2024-03-11</td>
      <td role="cell">South Kacie</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Noble</td>
      <td role="cell">Hickle</td>
      <td data-value="446601600000" role="cell" class="epp-ar">1984-02-26</td>
      <td role="cell">Runolfssonfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Montana</td>
      <td role="cell">Deckow</td>
      <td data-value="-199065600000" role="cell" class="epp-ar">1963-09-11</td>
      <td role="cell">North Laishahaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Dorris</td>
      <td role="cell">Lindgren</td>
      <td data-value="-96681600000" role="cell" class="epp-ar">1966-12-09</td>
      <td role="cell">Abshireton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Lina</td>
      <td role="cell">Hahn</td>
      <td data-value="1104796800000" role="cell" class="epp-ar">2005-01-04</td>
      <td role="cell">Quitzonport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Donnie</td>
      <td role="cell">Rolfson</td>
      <td data-value="1148774400000" role="cell" class="epp-ar">2006-05-28</td>
      <td role="cell">Nellaville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Alexandra</td>
      <td role="cell">Gerhold</td>
      <td data-value="618105600000" role="cell" class="epp-ar">1989-08-03</td>
      <td role="cell">East Clevelandmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Mack</td>
      <td role="cell">D'Amore</td>
      <td data-value="683856000000" role="cell" class="epp-ar">1991-09-03</td>
      <td role="cell">Ebonyfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Trace</td>
      <td role="cell">Raynor</td>
      <td data-value="1460678400000" role="cell" class="epp-ar">2016-04-15</td>
      <td role="cell">Hilperttown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Shany</td>
      <td role="cell">Luettgen</td>
      <td data-value="455155200000" role="cell" class="epp-ar">1984-06-04</td>
      <td role="cell">East Madisenchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Audreanne</td>
      <td role="cell">D'Amore</td>
      <td data-value="-221011200000" role="cell" class="epp-ar">1962-12-31</td>
      <td role="cell">East Lilianemouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Tobin</td>
      <td role="cell">Dibbert</td>
      <td data-value="-1986854400000" role="cell" class="epp-ar">1907-01-16</td>
      <td role="cell">Littleshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Logan</td>
      <td role="cell">Beer</td>
      <td data-value="1500854400000" role="cell" class="epp-ar">2017-07-24</td>
      <td role="cell">South Jesshaven</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;
}