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
England Georgette Bergnaum 1984-06-29 Port Lomachester
Scotland Althea Leannon 1987-07-15 South Jarrell
England Jordi Mitchell 1912-06-01 Lake Rossie
Wales Lora Hoppe 1972-06-20 Lake Chesley
England Estelle Hagenes 1993-01-29 Susiehaven
England Emmanuelle Hamill 1963-11-10 Violetteview
Northern Ireland Dudley Jerde 1955-05-13 Lake Deangeloport
England Christiana Romaguera 1986-12-27 East Torrance
Scotland Gerhard West 1908-03-02 Estefaniaton
Northern Ireland Adele Purdy 1946-01-03 Bernieside
Northern Ireland Myrna Keeling 1963-05-18 East Americo
Scotland Ivy Medhurst 1988-10-16 Evaberg
Northern Ireland Chaz Runolfsson 2017-08-02 East Schuylerside
Northern Ireland Torrey Anderson 1926-07-18 North Jarrellside
Wales Milford Fay 1952-11-24 North Julian
Northern Ireland Daron Oberbrunner 2002-10-12 West Omaview
Scotland Nelda Torp 1957-01-02 New Ottilie
Scotland Marisa Rolfson 2009-12-22 Spencerbury
England Brayan Gerlach 2010-05-01 Faheyfort
Wales Bobby Considine 1969-02-07 New Orvillemouth
Northern Ireland Aurore Gaylord 2008-10-18 Batzside
Scotland Daryl Wiegand 1981-06-17 South Fernborough
Scotland Rashawn Ritchie 1972-12-01 New Ludie
Wales Paolo Fay 1911-08-06 West Fernando
Northern Ireland Vicente Price 1970-08-29 West Rosamondshire
England Eriberto Hirthe 1978-10-11 Port Rickey
Scotland Aylin O'Kon 1996-02-21 Port Teagan
Wales Sigmund Lynch 1963-04-09 Lake Hortense
England Ena Feeney 1995-06-24 Lake Clintonfort
Wales Destany Wuckert 1989-03-06 Tillmanshire
Scotland Porter Senger 1954-06-06 East Keeley
Wales Neva Morissette 1945-08-19 Port Yazminport
Northern Ireland Lilly Torp 2009-03-13 Ashleighchester
Northern Ireland Bobbie Miller 1980-09-02 Lewchester
Wales Gaetano Hamill 1964-02-08 Kertzmannfort
Wales Jessyca Johnston 1970-04-19 Brownville
Scotland Ole Lemke 1977-09-27 Gradyton
Scotland Melyna Lindgren 1989-07-23 South Linda
Northern Ireland Anastacio Nader 1978-08-04 Keanuville
Wales Maria Veum 1921-05-25 Lake Nia
Scotland Hoyt Bins 1945-07-23 Kennedyfurt
England Priscilla O'Hara 1999-09-12 Wizachester
Northern Ireland Nestor Mohr 2010-03-03 Ondrickafort
Northern Ireland Daisha Glover 1947-07-21 East Pattiestad
Scotland Jarvis Carroll 1909-12-19 New Sydnie
Scotland Eula Swaniawski 1986-12-24 Eliseoborough
Wales Ron Hauck 1982-05-20 Monahaven
England Israel McKenzie 1996-07-10 North Kelley
Scotland Kamryn Bartell 1919-05-06 Russelmouth
Northern Ireland Rocky Breitenberg 1971-03-15 Carolton

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">England</td>
      <td role="cell">Georgette</td>
      <td role="cell">Bergnaum</td>
      <td data-value="457315200000" role="cell" class="epp-ar">1984-06-29</td>
      <td role="cell">Port Lomachester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Althea</td>
      <td role="cell">Leannon</td>
      <td data-value="553305600000" role="cell" class="epp-ar">1987-07-15</td>
      <td role="cell">South Jarrell</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Jordi</td>
      <td role="cell">Mitchell</td>
      <td data-value="-1817251200000" role="cell" class="epp-ar">1912-06-01</td>
      <td role="cell">Lake Rossie</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Lora</td>
      <td role="cell">Hoppe</td>
      <td data-value="77846400000" role="cell" class="epp-ar">1972-06-20</td>
      <td role="cell">Lake Chesley</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Estelle</td>
      <td role="cell">Hagenes</td>
      <td data-value="728265600000" role="cell" class="epp-ar">1993-01-29</td>
      <td role="cell">Susiehaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Emmanuelle</td>
      <td role="cell">Hamill</td>
      <td data-value="-193881600000" role="cell" class="epp-ar">1963-11-10</td>
      <td role="cell">Violetteview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Dudley</td>
      <td role="cell">Jerde</td>
      <td data-value="-461980800000" role="cell" class="epp-ar">1955-05-13</td>
      <td role="cell">Lake Deangeloport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Christiana</td>
      <td role="cell">Romaguera</td>
      <td data-value="536025600000" role="cell" class="epp-ar">1986-12-27</td>
      <td role="cell">East Torrance</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Gerhard</td>
      <td role="cell">West</td>
      <td data-value="-1951344000000" role="cell" class="epp-ar">1908-03-02</td>
      <td role="cell">Estefaniaton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Adele</td>
      <td role="cell">Purdy</td>
      <td data-value="-757209600000" role="cell" class="epp-ar">1946-01-03</td>
      <td role="cell">Bernieside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Myrna</td>
      <td role="cell">Keeling</td>
      <td data-value="-209088000000" role="cell" class="epp-ar">1963-05-18</td>
      <td role="cell">East Americo</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Ivy</td>
      <td role="cell">Medhurst</td>
      <td data-value="592963200000" role="cell" class="epp-ar">1988-10-16</td>
      <td role="cell">Evaberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Chaz</td>
      <td role="cell">Runolfsson</td>
      <td data-value="1501632000000" role="cell" class="epp-ar">2017-08-02</td>
      <td role="cell">East Schuylerside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Torrey</td>
      <td role="cell">Anderson</td>
      <td data-value="-1371427200000" role="cell" class="epp-ar">1926-07-18</td>
      <td role="cell">North Jarrellside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Milford</td>
      <td role="cell">Fay</td>
      <td data-value="-539740800000" role="cell" class="epp-ar">1952-11-24</td>
      <td role="cell">North Julian</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Daron</td>
      <td role="cell">Oberbrunner</td>
      <td data-value="1034380800000" role="cell" class="epp-ar">2002-10-12</td>
      <td role="cell">West Omaview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Nelda</td>
      <td role="cell">Torp</td>
      <td data-value="-410140800000" role="cell" class="epp-ar">1957-01-02</td>
      <td role="cell">New Ottilie</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Marisa</td>
      <td role="cell">Rolfson</td>
      <td data-value="1261440000000" role="cell" class="epp-ar">2009-12-22</td>
      <td role="cell">Spencerbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Brayan</td>
      <td role="cell">Gerlach</td>
      <td data-value="1272672000000" role="cell" class="epp-ar">2010-05-01</td>
      <td role="cell">Faheyfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Bobby</td>
      <td role="cell">Considine</td>
      <td data-value="-28339200000" role="cell" class="epp-ar">1969-02-07</td>
      <td role="cell">New Orvillemouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Aurore</td>
      <td role="cell">Gaylord</td>
      <td data-value="1224288000000" role="cell" class="epp-ar">2008-10-18</td>
      <td role="cell">Batzside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Daryl</td>
      <td role="cell">Wiegand</td>
      <td data-value="361584000000" role="cell" class="epp-ar">1981-06-17</td>
      <td role="cell">South Fernborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Rashawn</td>
      <td role="cell">Ritchie</td>
      <td data-value="92016000000" role="cell" class="epp-ar">1972-12-01</td>
      <td role="cell">New Ludie</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Paolo</td>
      <td role="cell">Fay</td>
      <td data-value="-1843171200000" role="cell" class="epp-ar">1911-08-06</td>
      <td role="cell">West Fernando</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Vicente</td>
      <td role="cell">Price</td>
      <td data-value="20736000000" role="cell" class="epp-ar">1970-08-29</td>
      <td role="cell">West Rosamondshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Eriberto</td>
      <td role="cell">Hirthe</td>
      <td data-value="276912000000" role="cell" class="epp-ar">1978-10-11</td>
      <td role="cell">Port Rickey</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Aylin</td>
      <td role="cell">O'Kon</td>
      <td data-value="824860800000" role="cell" class="epp-ar">1996-02-21</td>
      <td role="cell">Port Teagan</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Sigmund</td>
      <td role="cell">Lynch</td>
      <td data-value="-212457600000" role="cell" class="epp-ar">1963-04-09</td>
      <td role="cell">Lake Hortense</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Ena</td>
      <td role="cell">Feeney</td>
      <td data-value="803952000000" role="cell" class="epp-ar">1995-06-24</td>
      <td role="cell">Lake Clintonfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Destany</td>
      <td role="cell">Wuckert</td>
      <td data-value="605145600000" role="cell" class="epp-ar">1989-03-06</td>
      <td role="cell">Tillmanshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Porter</td>
      <td role="cell">Senger</td>
      <td data-value="-491443200000" role="cell" class="epp-ar">1954-06-06</td>
      <td role="cell">East Keeley</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Neva</td>
      <td role="cell">Morissette</td>
      <td data-value="-769046400000" role="cell" class="epp-ar">1945-08-19</td>
      <td role="cell">Port Yazminport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Lilly</td>
      <td role="cell">Torp</td>
      <td data-value="1236902400000" role="cell" class="epp-ar">2009-03-13</td>
      <td role="cell">Ashleighchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Bobbie</td>
      <td role="cell">Miller</td>
      <td data-value="336700800000" role="cell" class="epp-ar">1980-09-02</td>
      <td role="cell">Lewchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Gaetano</td>
      <td role="cell">Hamill</td>
      <td data-value="-186105600000" role="cell" class="epp-ar">1964-02-08</td>
      <td role="cell">Kertzmannfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Jessyca</td>
      <td role="cell">Johnston</td>
      <td data-value="9331200000" role="cell" class="epp-ar">1970-04-19</td>
      <td role="cell">Brownville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Ole</td>
      <td role="cell">Lemke</td>
      <td data-value="244166400000" role="cell" class="epp-ar">1977-09-27</td>
      <td role="cell">Gradyton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Melyna</td>
      <td role="cell">Lindgren</td>
      <td data-value="617155200000" role="cell" class="epp-ar">1989-07-23</td>
      <td role="cell">South Linda</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Anastacio</td>
      <td role="cell">Nader</td>
      <td data-value="271036800000" role="cell" class="epp-ar">1978-08-04</td>
      <td role="cell">Keanuville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Maria</td>
      <td role="cell">Veum</td>
      <td data-value="-1533859200000" role="cell" class="epp-ar">1921-05-25</td>
      <td role="cell">Lake Nia</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Hoyt</td>
      <td role="cell">Bins</td>
      <td data-value="-771379200000" role="cell" class="epp-ar">1945-07-23</td>
      <td role="cell">Kennedyfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Priscilla</td>
      <td role="cell">O'Hara</td>
      <td data-value="937094400000" role="cell" class="epp-ar">1999-09-12</td>
      <td role="cell">Wizachester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Nestor</td>
      <td role="cell">Mohr</td>
      <td data-value="1267574400000" role="cell" class="epp-ar">2010-03-03</td>
      <td role="cell">Ondrickafort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Daisha</td>
      <td role="cell">Glover</td>
      <td data-value="-708480000000" role="cell" class="epp-ar">1947-07-21</td>
      <td role="cell">East Pattiestad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jarvis</td>
      <td role="cell">Carroll</td>
      <td data-value="-1894579200000" role="cell" class="epp-ar">1909-12-19</td>
      <td role="cell">New Sydnie</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Eula</td>
      <td role="cell">Swaniawski</td>
      <td data-value="535766400000" role="cell" class="epp-ar">1986-12-24</td>
      <td role="cell">Eliseoborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Ron</td>
      <td role="cell">Hauck</td>
      <td data-value="390700800000" role="cell" class="epp-ar">1982-05-20</td>
      <td role="cell">Monahaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Israel</td>
      <td role="cell">McKenzie</td>
      <td data-value="836956800000" role="cell" class="epp-ar">1996-07-10</td>
      <td role="cell">North Kelley</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Kamryn</td>
      <td role="cell">Bartell</td>
      <td data-value="-1598659200000" role="cell" class="epp-ar">1919-05-06</td>
      <td role="cell">Russelmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Rocky</td>
      <td role="cell">Breitenberg</td>
      <td data-value="37843200000" role="cell" class="epp-ar">1971-03-15</td>
      <td role="cell">Carolton</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;
}