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 Abbigail Flatley 1952-07-13 New Eladiomouth
England Lacy Stracke 1948-10-12 South Ignatiusside
England Mekhi Quitzon 1945-03-03 Schneiderport
Wales Antonina Purdy 1941-05-12 Emilialand
Scotland Jonathon Nitzsche 1964-12-18 Hayleehaven
Northern Ireland Watson Homenick 2018-10-12 New Lilyanberg
Wales Violet Howell 2012-03-14 Lake Ashtyn
Northern Ireland Rene Hodkiewicz 1914-09-27 Durganmouth
England Fred Swaniawski 1975-05-06 Adeliatown
Scotland Alene Bernier 2017-03-26 Carlottamouth
Scotland Emmanuel Reynolds 1903-05-25 Mistybury
Wales Brock Grant 1944-06-16 Thompsonhaven
Scotland Abdullah Kessler 1987-09-29 Port Alexysberg
Scotland Hollis Williamson 1945-10-08 North Michelstad
Northern Ireland Micheal Langworth 1994-05-11 Elisabethborough
Wales Cory Stokes 2021-08-12 South Austinstad
Scotland Elaina Berge 1980-06-10 West Raleighhaven
Wales Cyril Gleichner 1956-01-18 North Jerry
Scotland Keshaun Hermiston 1968-10-05 Clotildestad
England Lois Shanahan 1959-01-27 West Gertrudefort
England Bettye Cummings 1953-04-24 Finnton
England Marjory Larson 1967-08-20 Port Hazelshire
England Naomi Rau 2006-04-25 Ovaborough
Wales Aaron Durgan 1998-12-23 Karolannview
Scotland Amya Kilback 1979-01-11 Lake Mathew
Northern Ireland Jack Schamberger 1931-09-11 West April
Wales Cara Berge 2010-09-03 Port Daniela
Northern Ireland Lennie Bergstrom 1913-04-12 Lake Jaleelland
Scotland Rachel Beahan 1964-07-03 East Erling
Northern Ireland Archibald Welch 1926-02-27 Chetchester
Scotland Diamond Marvin 1968-04-18 O'Konside
Scotland Bernita Wiegand 1974-04-18 Micahland
Northern Ireland Ramiro McCullough 1936-12-25 Bergnaumstad
Scotland Haleigh Weissnat 1965-05-22 North Trevorland
Northern Ireland Kade Wiza 1997-07-04 Metztown
England Rex Kautzer 1958-11-13 Lake Chaz
Wales Mateo Waters 2008-09-29 Davisport
England Alexander Kassulke 2016-10-30 South Elizabethborough
Wales Natalia Sporer 1929-08-22 Sengerberg
Scotland Edwin Yundt 1982-08-06 Maximomouth
Wales Raina Spinka 1948-12-04 Boehmstad
Wales Eileen Stamm 1918-02-24 South Trycia
Wales Nikita Hermiston 1967-02-15 Port Brendenmouth
Northern Ireland Camylle Runte 1966-09-10 Marquardtstad
Scotland Vance Cormier 1910-10-20 Kuhicchester
England Fanny Trantow 1964-09-04 Danielport
Wales Violette Toy 1910-07-06 Jaskolskiville
Scotland Rick Parker 1991-09-05 Hicklefurt
Wales Ella Bauch 1985-10-22 Altenwerthfort
Northern Ireland Alessandro Schmitt 1941-12-17 Dockfurt

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">Abbigail</td>
      <td role="cell">Flatley</td>
      <td data-value="-551318400000" role="cell" class="epp-ar">1952-07-13</td>
      <td role="cell">New Eladiomouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Lacy</td>
      <td role="cell">Stracke</td>
      <td data-value="-669686400000" role="cell" class="epp-ar">1948-10-12</td>
      <td role="cell">South Ignatiusside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Mekhi</td>
      <td role="cell">Quitzon</td>
      <td data-value="-783648000000" role="cell" class="epp-ar">1945-03-03</td>
      <td role="cell">Schneiderport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Antonina</td>
      <td role="cell">Purdy</td>
      <td data-value="-903830400000" role="cell" class="epp-ar">1941-05-12</td>
      <td role="cell">Emilialand</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jonathon</td>
      <td role="cell">Nitzsche</td>
      <td data-value="-158976000000" role="cell" class="epp-ar">1964-12-18</td>
      <td role="cell">Hayleehaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Watson</td>
      <td role="cell">Homenick</td>
      <td data-value="1539302400000" role="cell" class="epp-ar">2018-10-12</td>
      <td role="cell">New Lilyanberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Violet</td>
      <td role="cell">Howell</td>
      <td data-value="1331683200000" role="cell" class="epp-ar">2012-03-14</td>
      <td role="cell">Lake Ashtyn</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Rene</td>
      <td role="cell">Hodkiewicz</td>
      <td data-value="-1743984000000" role="cell" class="epp-ar">1914-09-27</td>
      <td role="cell">Durganmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Fred</td>
      <td role="cell">Swaniawski</td>
      <td data-value="168566400000" role="cell" class="epp-ar">1975-05-06</td>
      <td role="cell">Adeliatown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Alene</td>
      <td role="cell">Bernier</td>
      <td data-value="1490486400000" role="cell" class="epp-ar">2017-03-26</td>
      <td role="cell">Carlottamouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Emmanuel</td>
      <td role="cell">Reynolds</td>
      <td data-value="-2101939200000" role="cell" class="epp-ar">1903-05-25</td>
      <td role="cell">Mistybury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Brock</td>
      <td role="cell">Grant</td>
      <td data-value="-806112000000" role="cell" class="epp-ar">1944-06-16</td>
      <td role="cell">Thompsonhaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Abdullah</td>
      <td role="cell">Kessler</td>
      <td data-value="559872000000" role="cell" class="epp-ar">1987-09-29</td>
      <td role="cell">Port Alexysberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Hollis</td>
      <td role="cell">Williamson</td>
      <td data-value="-764726400000" role="cell" class="epp-ar">1945-10-08</td>
      <td role="cell">North Michelstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Micheal</td>
      <td role="cell">Langworth</td>
      <td data-value="768614400000" role="cell" class="epp-ar">1994-05-11</td>
      <td role="cell">Elisabethborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Cory</td>
      <td role="cell">Stokes</td>
      <td data-value="1628726400000" role="cell" class="epp-ar">2021-08-12</td>
      <td role="cell">South Austinstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Elaina</td>
      <td role="cell">Berge</td>
      <td data-value="329443200000" role="cell" class="epp-ar">1980-06-10</td>
      <td role="cell">West Raleighhaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Cyril</td>
      <td role="cell">Gleichner</td>
      <td data-value="-440380800000" role="cell" class="epp-ar">1956-01-18</td>
      <td role="cell">North Jerry</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Keshaun</td>
      <td role="cell">Hermiston</td>
      <td data-value="-39139200000" role="cell" class="epp-ar">1968-10-05</td>
      <td role="cell">Clotildestad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Lois</td>
      <td role="cell">Shanahan</td>
      <td data-value="-344908800000" role="cell" class="epp-ar">1959-01-27</td>
      <td role="cell">West Gertrudefort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Bettye</td>
      <td role="cell">Cummings</td>
      <td data-value="-526694400000" role="cell" class="epp-ar">1953-04-24</td>
      <td role="cell">Finnton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Marjory</td>
      <td role="cell">Larson</td>
      <td data-value="-74736000000" role="cell" class="epp-ar">1967-08-20</td>
      <td role="cell">Port Hazelshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Naomi</td>
      <td role="cell">Rau</td>
      <td data-value="1145923200000" role="cell" class="epp-ar">2006-04-25</td>
      <td role="cell">Ovaborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Aaron</td>
      <td role="cell">Durgan</td>
      <td data-value="914371200000" role="cell" class="epp-ar">1998-12-23</td>
      <td role="cell">Karolannview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Amya</td>
      <td role="cell">Kilback</td>
      <td data-value="284860800000" role="cell" class="epp-ar">1979-01-11</td>
      <td role="cell">Lake Mathew</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jack</td>
      <td role="cell">Schamberger</td>
      <td data-value="-1208908800000" role="cell" class="epp-ar">1931-09-11</td>
      <td role="cell">West April</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Cara</td>
      <td role="cell">Berge</td>
      <td data-value="1283472000000" role="cell" class="epp-ar">2010-09-03</td>
      <td role="cell">Port Daniela</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Lennie</td>
      <td role="cell">Bergstrom</td>
      <td data-value="-1790035200000" role="cell" class="epp-ar">1913-04-12</td>
      <td role="cell">Lake Jaleelland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Rachel</td>
      <td role="cell">Beahan</td>
      <td data-value="-173491200000" role="cell" class="epp-ar">1964-07-03</td>
      <td role="cell">East Erling</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Archibald</td>
      <td role="cell">Welch</td>
      <td data-value="-1383609600000" role="cell" class="epp-ar">1926-02-27</td>
      <td role="cell">Chetchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Diamond</td>
      <td role="cell">Marvin</td>
      <td data-value="-53827200000" role="cell" class="epp-ar">1968-04-18</td>
      <td role="cell">O'Konside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Bernita</td>
      <td role="cell">Wiegand</td>
      <td data-value="135475200000" role="cell" class="epp-ar">1974-04-18</td>
      <td role="cell">Micahland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Ramiro</td>
      <td role="cell">McCullough</td>
      <td data-value="-1041984000000" role="cell" class="epp-ar">1936-12-25</td>
      <td role="cell">Bergnaumstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Haleigh</td>
      <td role="cell">Weissnat</td>
      <td data-value="-145584000000" role="cell" class="epp-ar">1965-05-22</td>
      <td role="cell">North Trevorland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Kade</td>
      <td role="cell">Wiza</td>
      <td data-value="867974400000" role="cell" class="epp-ar">1997-07-04</td>
      <td role="cell">Metztown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Rex</td>
      <td role="cell">Kautzer</td>
      <td data-value="-351388800000" role="cell" class="epp-ar">1958-11-13</td>
      <td role="cell">Lake Chaz</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Mateo</td>
      <td role="cell">Waters</td>
      <td data-value="1222646400000" role="cell" class="epp-ar">2008-09-29</td>
      <td role="cell">Davisport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Alexander</td>
      <td role="cell">Kassulke</td>
      <td data-value="1477785600000" role="cell" class="epp-ar">2016-10-30</td>
      <td role="cell">South Elizabethborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Natalia</td>
      <td role="cell">Sporer</td>
      <td data-value="-1273708800000" role="cell" class="epp-ar">1929-08-22</td>
      <td role="cell">Sengerberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Edwin</td>
      <td role="cell">Yundt</td>
      <td data-value="397440000000" role="cell" class="epp-ar">1982-08-06</td>
      <td role="cell">Maximomouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Raina</td>
      <td role="cell">Spinka</td>
      <td data-value="-665107200000" role="cell" class="epp-ar">1948-12-04</td>
      <td role="cell">Boehmstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Eileen</td>
      <td role="cell">Stamm</td>
      <td data-value="-1636329600000" role="cell" class="epp-ar">1918-02-24</td>
      <td role="cell">South Trycia</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Nikita</td>
      <td role="cell">Hermiston</td>
      <td data-value="-90806400000" role="cell" class="epp-ar">1967-02-15</td>
      <td role="cell">Port Brendenmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Camylle</td>
      <td role="cell">Runte</td>
      <td data-value="-104457600000" role="cell" class="epp-ar">1966-09-10</td>
      <td role="cell">Marquardtstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Vance</td>
      <td role="cell">Cormier</td>
      <td data-value="-1868227200000" role="cell" class="epp-ar">1910-10-20</td>
      <td role="cell">Kuhicchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Fanny</td>
      <td role="cell">Trantow</td>
      <td data-value="-168048000000" role="cell" class="epp-ar">1964-09-04</td>
      <td role="cell">Danielport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Violette</td>
      <td role="cell">Toy</td>
      <td data-value="-1877385600000" role="cell" class="epp-ar">1910-07-06</td>
      <td role="cell">Jaskolskiville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Rick</td>
      <td role="cell">Parker</td>
      <td data-value="684028800000" role="cell" class="epp-ar">1991-09-05</td>
      <td role="cell">Hicklefurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Ella</td>
      <td role="cell">Bauch</td>
      <td data-value="498787200000" role="cell" class="epp-ar">1985-10-22</td>
      <td role="cell">Altenwerthfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Alessandro</td>
      <td role="cell">Schmitt</td>
      <td data-value="-884908800000" role="cell" class="epp-ar">1941-12-17</td>
      <td role="cell">Dockfurt</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;
}