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 Fredy Boehm 1938-08-09 North Leanne
Northern Ireland Mara Stroman 1965-02-18 New Lulafort
England Rey Stanton 1920-11-19 Reidport
Wales Arlene Steuber 2008-12-24 Port Robertaport
England Vaughn McLaughlin 1908-02-25 Hermanbury
Scotland Gerda Gutmann 1944-03-04 North Priscillafort
Scotland Madelyn Marvin 1944-05-30 Lake Adalbertohaven
Scotland Name Haley 1934-10-01 Laishaport
Scotland Sid Rempel 1989-07-09 Lake Bonita
Northern Ireland Humberto Kautzer 1971-09-01 North Samara
Scotland Columbus Goyette 1921-03-24 Ryanshire
Scotland Aaron Spinka 1965-07-17 South Ramona
Scotland Greyson Shanahan 1907-06-14 Cruickshankfort
Scotland Heidi Hoeger 1929-06-13 Franeckiview
Northern Ireland Vita Upton 1933-03-02 Johathanstad
Scotland Marcelino Torphy 1958-01-26 North Marcia
Scotland Marie Kulas 1964-10-27 Powlowskimouth
Northern Ireland Blanca Crist 2021-06-07 Alexisfort
Northern Ireland Onie Flatley 1925-03-08 Roweland
England Audrey Ankunding 2010-05-14 Lake Victor
Northern Ireland Elva Hegmann 2005-11-16 New Watson
Northern Ireland Eula Jacobi 1983-05-17 Creminfort
England Zander Osinski 1918-03-22 South Melliefort
Scotland Gerson Rohan 1923-07-20 Patsyton
England Alice Botsford 1934-01-19 Lake Christop
Scotland Luigi Collier 2021-04-11 West Robbmouth
Wales Erica Reichel 1916-12-20 New Ramiroview
England Summer Flatley 1955-08-31 West Henrietteburgh
Wales Blaze O'Keefe 1955-05-10 Casperburgh
Wales Benjamin Windler 2014-11-09 Loweborough
Scotland Aron Kovacek 1909-08-25 Port Cristalberg
Wales Willis Senger 1984-09-01 Quigleyfort
Scotland Carolanne Lehner 1961-05-06 Arnaldofort
Scotland Alessia Lubowitz 1989-11-13 Port Amiya
Northern Ireland Trace Lesch 1980-10-03 Ikefurt
Wales Brett Mosciski 2001-08-19 East Bailee
Northern Ireland Wayne Hermann 1963-05-19 Maryland
England Keegan Kassulke 1992-11-22 South Adeline
Wales Oral Kris 1986-09-27 Zettaland
England Elizabeth Beer 1971-04-16 West Tom
England Oma Corwin 1933-12-30 East Mariane
Scotland Erika Huel 1980-10-04 Port Frances
Wales Clinton Mayert 1962-03-09 Rauton
England Horace Lang 2014-07-23 Quitzonstad
England Isidro Sporer 1954-11-24 East Juanitatown
Scotland Rosie Nolan 1907-10-08 Lake Valentine
Wales Krystina Hilpert 1998-02-06 Lake Lutherchester
Scotland Virgie Nitzsche 1971-05-14 West Clementina
Northern Ireland Shaniya Lehner 2016-10-20 Port Alenefurt
Northern Ireland Joelle Hintz 1926-05-08 North Valentinastad

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">Fredy</td>
      <td role="cell">Boehm</td>
      <td data-value="-990835200000" role="cell" class="epp-ar">1938-08-09</td>
      <td role="cell">North Leanne</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Mara</td>
      <td role="cell">Stroman</td>
      <td data-value="-153619200000" role="cell" class="epp-ar">1965-02-18</td>
      <td role="cell">New Lulafort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Rey</td>
      <td role="cell">Stanton</td>
      <td data-value="-1550016000000" role="cell" class="epp-ar">1920-11-19</td>
      <td role="cell">Reidport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Arlene</td>
      <td role="cell">Steuber</td>
      <td data-value="1230076800000" role="cell" class="epp-ar">2008-12-24</td>
      <td role="cell">Port Robertaport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Vaughn</td>
      <td role="cell">McLaughlin</td>
      <td data-value="-1951862400000" role="cell" class="epp-ar">1908-02-25</td>
      <td role="cell">Hermanbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Gerda</td>
      <td role="cell">Gutmann</td>
      <td data-value="-815097600000" role="cell" class="epp-ar">1944-03-04</td>
      <td role="cell">North Priscillafort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Madelyn</td>
      <td role="cell">Marvin</td>
      <td data-value="-807580800000" role="cell" class="epp-ar">1944-05-30</td>
      <td role="cell">Lake Adalbertohaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Name</td>
      <td role="cell">Haley</td>
      <td data-value="-1112486400000" role="cell" class="epp-ar">1934-10-01</td>
      <td role="cell">Laishaport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Sid</td>
      <td role="cell">Rempel</td>
      <td data-value="615945600000" role="cell" class="epp-ar">1989-07-09</td>
      <td role="cell">Lake Bonita</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Humberto</td>
      <td role="cell">Kautzer</td>
      <td data-value="52531200000" role="cell" class="epp-ar">1971-09-01</td>
      <td role="cell">North Samara</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Columbus</td>
      <td role="cell">Goyette</td>
      <td data-value="-1539216000000" role="cell" class="epp-ar">1921-03-24</td>
      <td role="cell">Ryanshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Aaron</td>
      <td role="cell">Spinka</td>
      <td data-value="-140745600000" role="cell" class="epp-ar">1965-07-17</td>
      <td role="cell">South Ramona</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Greyson</td>
      <td role="cell">Shanahan</td>
      <td data-value="-1973980800000" role="cell" class="epp-ar">1907-06-14</td>
      <td role="cell">Cruickshankfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Heidi</td>
      <td role="cell">Hoeger</td>
      <td data-value="-1279756800000" role="cell" class="epp-ar">1929-06-13</td>
      <td role="cell">Franeckiview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Vita</td>
      <td role="cell">Upton</td>
      <td data-value="-1162425600000" role="cell" class="epp-ar">1933-03-02</td>
      <td role="cell">Johathanstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Marcelino</td>
      <td role="cell">Torphy</td>
      <td data-value="-376531200000" role="cell" class="epp-ar">1958-01-26</td>
      <td role="cell">North Marcia</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Marie</td>
      <td role="cell">Kulas</td>
      <td data-value="-163468800000" role="cell" class="epp-ar">1964-10-27</td>
      <td role="cell">Powlowskimouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Blanca</td>
      <td role="cell">Crist</td>
      <td data-value="1623024000000" role="cell" class="epp-ar">2021-06-07</td>
      <td role="cell">Alexisfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Onie</td>
      <td role="cell">Flatley</td>
      <td data-value="-1414368000000" role="cell" class="epp-ar">1925-03-08</td>
      <td role="cell">Roweland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Audrey</td>
      <td role="cell">Ankunding</td>
      <td data-value="1273795200000" role="cell" class="epp-ar">2010-05-14</td>
      <td role="cell">Lake Victor</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Elva</td>
      <td role="cell">Hegmann</td>
      <td data-value="1132099200000" role="cell" class="epp-ar">2005-11-16</td>
      <td role="cell">New Watson</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Eula</td>
      <td role="cell">Jacobi</td>
      <td data-value="421977600000" role="cell" class="epp-ar">1983-05-17</td>
      <td role="cell">Creminfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Zander</td>
      <td role="cell">Osinski</td>
      <td data-value="-1634083200000" role="cell" class="epp-ar">1918-03-22</td>
      <td role="cell">South Melliefort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Gerson</td>
      <td role="cell">Rohan</td>
      <td data-value="-1465948800000" role="cell" class="epp-ar">1923-07-20</td>
      <td role="cell">Patsyton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Alice</td>
      <td role="cell">Botsford</td>
      <td data-value="-1134518400000" role="cell" class="epp-ar">1934-01-19</td>
      <td role="cell">Lake Christop</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Luigi</td>
      <td role="cell">Collier</td>
      <td data-value="1618099200000" role="cell" class="epp-ar">2021-04-11</td>
      <td role="cell">West Robbmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Erica</td>
      <td role="cell">Reichel</td>
      <td data-value="-1673568000000" role="cell" class="epp-ar">1916-12-20</td>
      <td role="cell">New Ramiroview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Summer</td>
      <td role="cell">Flatley</td>
      <td data-value="-452476800000" role="cell" class="epp-ar">1955-08-31</td>
      <td role="cell">West Henrietteburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Blaze</td>
      <td role="cell">O'Keefe</td>
      <td data-value="-462240000000" role="cell" class="epp-ar">1955-05-10</td>
      <td role="cell">Casperburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Benjamin</td>
      <td role="cell">Windler</td>
      <td data-value="1415491200000" role="cell" class="epp-ar">2014-11-09</td>
      <td role="cell">Loweborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Aron</td>
      <td role="cell">Kovacek</td>
      <td data-value="-1904601600000" role="cell" class="epp-ar">1909-08-25</td>
      <td role="cell">Port Cristalberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Willis</td>
      <td role="cell">Senger</td>
      <td data-value="462844800000" role="cell" class="epp-ar">1984-09-01</td>
      <td role="cell">Quigleyfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Carolanne</td>
      <td role="cell">Lehner</td>
      <td data-value="-273196800000" role="cell" class="epp-ar">1961-05-06</td>
      <td role="cell">Arnaldofort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Alessia</td>
      <td role="cell">Lubowitz</td>
      <td data-value="626918400000" role="cell" class="epp-ar">1989-11-13</td>
      <td role="cell">Port Amiya</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Trace</td>
      <td role="cell">Lesch</td>
      <td data-value="339379200000" role="cell" class="epp-ar">1980-10-03</td>
      <td role="cell">Ikefurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Brett</td>
      <td role="cell">Mosciski</td>
      <td data-value="998179200000" role="cell" class="epp-ar">2001-08-19</td>
      <td role="cell">East Bailee</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Wayne</td>
      <td role="cell">Hermann</td>
      <td data-value="-209001600000" role="cell" class="epp-ar">1963-05-19</td>
      <td role="cell">Maryland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Keegan</td>
      <td role="cell">Kassulke</td>
      <td data-value="722390400000" role="cell" class="epp-ar">1992-11-22</td>
      <td role="cell">South Adeline</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Oral</td>
      <td role="cell">Kris</td>
      <td data-value="528163200000" role="cell" class="epp-ar">1986-09-27</td>
      <td role="cell">Zettaland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Elizabeth</td>
      <td role="cell">Beer</td>
      <td data-value="40608000000" role="cell" class="epp-ar">1971-04-16</td>
      <td role="cell">West Tom</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Oma</td>
      <td role="cell">Corwin</td>
      <td data-value="-1136246400000" role="cell" class="epp-ar">1933-12-30</td>
      <td role="cell">East Mariane</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Erika</td>
      <td role="cell">Huel</td>
      <td data-value="339465600000" role="cell" class="epp-ar">1980-10-04</td>
      <td role="cell">Port Frances</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Clinton</td>
      <td role="cell">Mayert</td>
      <td data-value="-246672000000" role="cell" class="epp-ar">1962-03-09</td>
      <td role="cell">Rauton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Horace</td>
      <td role="cell">Lang</td>
      <td data-value="1406073600000" role="cell" class="epp-ar">2014-07-23</td>
      <td role="cell">Quitzonstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Isidro</td>
      <td role="cell">Sporer</td>
      <td data-value="-476668800000" role="cell" class="epp-ar">1954-11-24</td>
      <td role="cell">East Juanitatown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Rosie</td>
      <td role="cell">Nolan</td>
      <td data-value="-1963958400000" role="cell" class="epp-ar">1907-10-08</td>
      <td role="cell">Lake Valentine</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Krystina</td>
      <td role="cell">Hilpert</td>
      <td data-value="886723200000" role="cell" class="epp-ar">1998-02-06</td>
      <td role="cell">Lake Lutherchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Virgie</td>
      <td role="cell">Nitzsche</td>
      <td data-value="43027200000" role="cell" class="epp-ar">1971-05-14</td>
      <td role="cell">West Clementina</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Shaniya</td>
      <td role="cell">Lehner</td>
      <td data-value="1476921600000" role="cell" class="epp-ar">2016-10-20</td>
      <td role="cell">Port Alenefurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Joelle</td>
      <td role="cell">Hintz</td>
      <td data-value="-1377561600000" role="cell" class="epp-ar">1926-05-08</td>
      <td role="cell">North Valentinastad</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;
}