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 Erin Feeney 1980-11-30 Marlonchester
England Anthony Friesen 1980-08-06 Lake Haleigh
Wales Verdie Schamberger 1965-08-24 Port Abnerland
Wales Chasity Hahn 1963-10-02 East Stacystad
Wales Alanis Marquardt 1981-08-12 Kirkburgh
Wales Jacquelyn Willms 1970-04-02 Raheemburgh
Scotland Ewald Labadie 1979-01-20 New Elisa
England Quincy Feil 1964-07-12 Budton
Scotland Eric Waelchi 2005-11-20 Port Salma
Scotland Autumn Hoppe 1994-12-24 New Alize
Northern Ireland Elwin Hirthe 2009-12-01 Vontown
England Connie Hartmann 2003-04-13 Spinkatown
Northern Ireland Timmy Schimmel 1966-01-19 Lake Seth
Northern Ireland Kenneth Sauer 1980-01-08 Nicoletteburgh
Scotland Kathleen Nader 2000-03-15 West Pinkie
Northern Ireland Jaime Bernhard 1932-05-25 South Rudyborough
Northern Ireland Stan Powlowski 1957-03-10 New Imaniville
Scotland Dave Smith 1969-01-19 Lake Evan
England Deven Schuppe 1963-11-30 West Euna
Scotland Ruthie Zboncak 2017-11-22 Schadenville
Northern Ireland Summer Schimmel 1997-01-08 Rennermouth
Northern Ireland Kamren Moen 1938-04-09 New Mayaville
Scotland Justina Klocko 1972-08-24 Erikamouth
Wales Rasheed Hirthe 1981-10-14 South Bernadineburgh
Northern Ireland Viola Connelly 1997-08-30 Lake Haylie
Northern Ireland Madyson Klein 1919-12-18 South Magnolia
Wales Nelle Kovacek 1947-07-26 Harrisland
Northern Ireland Joe Kuvalis 1970-11-25 West Willishaven
England Ayden Gislason 1964-09-08 Melyssastad
Northern Ireland Graciela Hilll 1973-01-20 New Bradfordburgh
Northern Ireland Garnet Kutch 2015-03-27 Littelmouth
Wales Bret Wiegand 2020-09-11 North Hilda
Scotland Lorna Runte 1963-11-19 Noeliaside
Northern Ireland Weston Cruickshank 1985-01-25 Geraldinetown
Wales Marjory Gleichner 1919-07-29 Buckridgeshire
Wales Sarah Bahringer 2015-09-24 West Harmony
England Darrin Zulauf 1973-11-20 Thadfurt
Wales Efrain Nolan 2003-12-22 West Lauraberg
Wales Carolanne Braun 1907-02-11 New Nicolette
Northern Ireland Ara Kessler 1990-06-17 West Constancetown
Northern Ireland Verlie Bauch 1964-05-18 Lake Claudport
Scotland Melvina Howell 1960-04-12 Lucasborough
England Bennett Prohaska 1985-01-26 Stantonton
Scotland Jacquelyn Torp 1910-08-16 West Sydneeborough
Northern Ireland Ofelia Rempel 1987-10-04 Angeloshire
Wales Mazie Ryan 2010-02-16 Giaborough
England Theo Padberg 1964-02-27 West Jeanette
Wales Douglas Bergstrom 1992-08-30 East Francoville
Northern Ireland Brad Schuppe 1997-01-22 Camronshire
England Phoebe Lueilwitz 1937-04-15 East Michaelamouth

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">Erin</td>
      <td role="cell">Feeney</td>
      <td data-value="344390400000" role="cell" class="epp-ar">1980-11-30</td>
      <td role="cell">Marlonchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Anthony</td>
      <td role="cell">Friesen</td>
      <td data-value="334368000000" role="cell" class="epp-ar">1980-08-06</td>
      <td role="cell">Lake Haleigh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Verdie</td>
      <td role="cell">Schamberger</td>
      <td data-value="-137462400000" role="cell" class="epp-ar">1965-08-24</td>
      <td role="cell">Port Abnerland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Chasity</td>
      <td role="cell">Hahn</td>
      <td data-value="-197251200000" role="cell" class="epp-ar">1963-10-02</td>
      <td role="cell">East Stacystad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Alanis</td>
      <td role="cell">Marquardt</td>
      <td data-value="366422400000" role="cell" class="epp-ar">1981-08-12</td>
      <td role="cell">Kirkburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Jacquelyn</td>
      <td role="cell">Willms</td>
      <td data-value="7862400000" role="cell" class="epp-ar">1970-04-02</td>
      <td role="cell">Raheemburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Ewald</td>
      <td role="cell">Labadie</td>
      <td data-value="285638400000" role="cell" class="epp-ar">1979-01-20</td>
      <td role="cell">New Elisa</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Quincy</td>
      <td role="cell">Feil</td>
      <td data-value="-172713600000" role="cell" class="epp-ar">1964-07-12</td>
      <td role="cell">Budton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Eric</td>
      <td role="cell">Waelchi</td>
      <td data-value="1132444800000" role="cell" class="epp-ar">2005-11-20</td>
      <td role="cell">Port Salma</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Autumn</td>
      <td role="cell">Hoppe</td>
      <td data-value="788227200000" role="cell" class="epp-ar">1994-12-24</td>
      <td role="cell">New Alize</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Elwin</td>
      <td role="cell">Hirthe</td>
      <td data-value="1259625600000" role="cell" class="epp-ar">2009-12-01</td>
      <td role="cell">Vontown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Connie</td>
      <td role="cell">Hartmann</td>
      <td data-value="1050192000000" role="cell" class="epp-ar">2003-04-13</td>
      <td role="cell">Spinkatown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Timmy</td>
      <td role="cell">Schimmel</td>
      <td data-value="-124675200000" role="cell" class="epp-ar">1966-01-19</td>
      <td role="cell">Lake Seth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Kenneth</td>
      <td role="cell">Sauer</td>
      <td data-value="316137600000" role="cell" class="epp-ar">1980-01-08</td>
      <td role="cell">Nicoletteburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Kathleen</td>
      <td role="cell">Nader</td>
      <td data-value="953078400000" role="cell" class="epp-ar">2000-03-15</td>
      <td role="cell">West Pinkie</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jaime</td>
      <td role="cell">Bernhard</td>
      <td data-value="-1186704000000" role="cell" class="epp-ar">1932-05-25</td>
      <td role="cell">South Rudyborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Stan</td>
      <td role="cell">Powlowski</td>
      <td data-value="-404352000000" role="cell" class="epp-ar">1957-03-10</td>
      <td role="cell">New Imaniville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Dave</td>
      <td role="cell">Smith</td>
      <td data-value="-29980800000" role="cell" class="epp-ar">1969-01-19</td>
      <td role="cell">Lake Evan</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Deven</td>
      <td role="cell">Schuppe</td>
      <td data-value="-192153600000" role="cell" class="epp-ar">1963-11-30</td>
      <td role="cell">West Euna</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Ruthie</td>
      <td role="cell">Zboncak</td>
      <td data-value="1511308800000" role="cell" class="epp-ar">2017-11-22</td>
      <td role="cell">Schadenville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Summer</td>
      <td role="cell">Schimmel</td>
      <td data-value="852681600000" role="cell" class="epp-ar">1997-01-08</td>
      <td role="cell">Rennermouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Kamren</td>
      <td role="cell">Moen</td>
      <td data-value="-1001376000000" role="cell" class="epp-ar">1938-04-09</td>
      <td role="cell">New Mayaville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Justina</td>
      <td role="cell">Klocko</td>
      <td data-value="83462400000" role="cell" class="epp-ar">1972-08-24</td>
      <td role="cell">Erikamouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Rasheed</td>
      <td role="cell">Hirthe</td>
      <td data-value="371865600000" role="cell" class="epp-ar">1981-10-14</td>
      <td role="cell">South Bernadineburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Viola</td>
      <td role="cell">Connelly</td>
      <td data-value="872899200000" role="cell" class="epp-ar">1997-08-30</td>
      <td role="cell">Lake Haylie</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Madyson</td>
      <td role="cell">Klein</td>
      <td data-value="-1579132800000" role="cell" class="epp-ar">1919-12-18</td>
      <td role="cell">South Magnolia</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Nelle</td>
      <td role="cell">Kovacek</td>
      <td data-value="-708048000000" role="cell" class="epp-ar">1947-07-26</td>
      <td role="cell">Harrisland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Joe</td>
      <td role="cell">Kuvalis</td>
      <td data-value="28339200000" role="cell" class="epp-ar">1970-11-25</td>
      <td role="cell">West Willishaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Ayden</td>
      <td role="cell">Gislason</td>
      <td data-value="-167702400000" role="cell" class="epp-ar">1964-09-08</td>
      <td role="cell">Melyssastad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Graciela</td>
      <td role="cell">Hilll</td>
      <td data-value="96336000000" role="cell" class="epp-ar">1973-01-20</td>
      <td role="cell">New Bradfordburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Garnet</td>
      <td role="cell">Kutch</td>
      <td data-value="1427414400000" role="cell" class="epp-ar">2015-03-27</td>
      <td role="cell">Littelmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Bret</td>
      <td role="cell">Wiegand</td>
      <td data-value="1599782400000" role="cell" class="epp-ar">2020-09-11</td>
      <td role="cell">North Hilda</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Lorna</td>
      <td role="cell">Runte</td>
      <td data-value="-193104000000" role="cell" class="epp-ar">1963-11-19</td>
      <td role="cell">Noeliaside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Weston</td>
      <td role="cell">Cruickshank</td>
      <td data-value="475459200000" role="cell" class="epp-ar">1985-01-25</td>
      <td role="cell">Geraldinetown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Marjory</td>
      <td role="cell">Gleichner</td>
      <td data-value="-1591401600000" role="cell" class="epp-ar">1919-07-29</td>
      <td role="cell">Buckridgeshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Sarah</td>
      <td role="cell">Bahringer</td>
      <td data-value="1443052800000" role="cell" class="epp-ar">2015-09-24</td>
      <td role="cell">West Harmony</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Darrin</td>
      <td role="cell">Zulauf</td>
      <td data-value="122601600000" role="cell" class="epp-ar">1973-11-20</td>
      <td role="cell">Thadfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Efrain</td>
      <td role="cell">Nolan</td>
      <td data-value="1072051200000" role="cell" class="epp-ar">2003-12-22</td>
      <td role="cell">West Lauraberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Carolanne</td>
      <td role="cell">Braun</td>
      <td data-value="-1984608000000" role="cell" class="epp-ar">1907-02-11</td>
      <td role="cell">New Nicolette</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Ara</td>
      <td role="cell">Kessler</td>
      <td data-value="645580800000" role="cell" class="epp-ar">1990-06-17</td>
      <td role="cell">West Constancetown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Verlie</td>
      <td role="cell">Bauch</td>
      <td data-value="-177465600000" role="cell" class="epp-ar">1964-05-18</td>
      <td role="cell">Lake Claudport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Melvina</td>
      <td role="cell">Howell</td>
      <td data-value="-306806400000" role="cell" class="epp-ar">1960-04-12</td>
      <td role="cell">Lucasborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Bennett</td>
      <td role="cell">Prohaska</td>
      <td data-value="475545600000" role="cell" class="epp-ar">1985-01-26</td>
      <td role="cell">Stantonton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jacquelyn</td>
      <td role="cell">Torp</td>
      <td data-value="-1873843200000" role="cell" class="epp-ar">1910-08-16</td>
      <td role="cell">West Sydneeborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Ofelia</td>
      <td role="cell">Rempel</td>
      <td data-value="560304000000" role="cell" class="epp-ar">1987-10-04</td>
      <td role="cell">Angeloshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Mazie</td>
      <td role="cell">Ryan</td>
      <td data-value="1266278400000" role="cell" class="epp-ar">2010-02-16</td>
      <td role="cell">Giaborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Theo</td>
      <td role="cell">Padberg</td>
      <td data-value="-184464000000" role="cell" class="epp-ar">1964-02-27</td>
      <td role="cell">West Jeanette</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Douglas</td>
      <td role="cell">Bergstrom</td>
      <td data-value="715132800000" role="cell" class="epp-ar">1992-08-30</td>
      <td role="cell">East Francoville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Brad</td>
      <td role="cell">Schuppe</td>
      <td data-value="853891200000" role="cell" class="epp-ar">1997-01-22</td>
      <td role="cell">Camronshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Phoebe</td>
      <td role="cell">Lueilwitz</td>
      <td data-value="-1032393600000" role="cell" class="epp-ar">1937-04-15</td>
      <td role="cell">East Michaelamouth</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;
}