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 Charlotte Bednar 1919-08-22 East Llewellynside
Northern Ireland Orin Barton 2008-12-24 South Delpha
England Reece Langworth 2004-12-02 Strackeview
Northern Ireland Lisandro O'Connell 1935-01-08 East Scot
Wales Kari Zemlak 1991-01-22 Gutmannbury
Scotland Jettie Heaney 2000-06-07 Jacklynport
Northern Ireland Raleigh Turner 1990-01-29 Lake Candidohaven
Northern Ireland Eduardo Gusikowski 1988-02-15 New Crystalbury
Northern Ireland Bryana Zieme 1993-08-03 Port Jessicatown
Wales Dagmar Hudson 1959-01-17 Buckchester
Wales Elva Koss 1998-02-07 North Ofeliaton
Northern Ireland Vergie Cronin 2005-01-06 Jeramyberg
England Americo Tillman 1976-04-18 Alleneburgh
Scotland Damaris Hamill 1965-03-15 North Orlandshire
England Scot Kris 2016-04-25 Whiteside
Wales Nasir Ondricka 1999-02-20 Flatleyport
Wales Irwin D'Amore 1965-01-01 Tobinshire
Scotland Seamus Blanda 1921-12-19 West Mae
Wales Jeff Murray 1965-05-26 North Davontechester
England Gaetano Lesch 1965-01-03 South Jedediah
Scotland Aimee Cummings 1905-02-02 Rigobertomouth
England Ivory Medhurst 1965-06-29 North Colton
Wales Deondre Anderson 1952-02-11 New Otiliaport
England Jimmy Rogahn 1964-08-17 North Herta
Wales Mckenzie Goodwin 1957-03-28 Carolinatown
England Sean Hessel 1947-09-14 South Bobby
Scotland Moriah Mills 1974-12-01 East Ryleighberg
England Keira Jacobson 1950-02-26 Lake Rodgertown
England Clementina Windler 1924-12-14 South Agnesstad
Scotland Tito Wintheiser 1909-08-21 Larsonfort
Scotland Erwin Batz 1991-01-01 West Courtney
Scotland Keely Lang 1947-03-05 Lake Murraytown
Northern Ireland Alexandrine Kuhic 2021-12-27 Lake Nils
Wales Zoey Ruecker 1965-07-07 Wittingland
Scotland Leslie Balistreri 1979-03-15 Edmondville
Scotland Carroll Littel 2020-08-22 Percystad
Scotland Thea Stroman 1972-02-22 North Shanashire
England Fatima Kunze 1943-05-27 Port Nicholas
Wales Laurianne Hauck 1946-07-04 West Eliborough
Northern Ireland Kian Zboncak 2002-03-31 Jerrellside
Northern Ireland Adelle Kuhlman 1950-07-03 New Curtis
Northern Ireland Alfred Towne 1930-08-23 Marianneview
Scotland Alfreda Hamill 1975-10-27 Valerieside
Scotland Corine Johnston 1967-01-30 Altaberg
Northern Ireland Marjorie Goyette 1978-09-04 West Corinefort
Scotland Sadye Stanton 2007-04-27 Abbottfurt
Scotland Stewart Schimmel 1957-09-15 Isidroport
Scotland Scarlett Schaden 1948-10-27 Weberville
Scotland Darian Mueller 1961-01-03 O'Keefeview
Scotland Hector Hilpert 2010-06-19 Skileshaven

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">Charlotte</td>
      <td role="cell">Bednar</td>
      <td data-value="-1589328000000" role="cell" class="epp-ar">1919-08-22</td>
      <td role="cell">East Llewellynside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Orin</td>
      <td role="cell">Barton</td>
      <td data-value="1230076800000" role="cell" class="epp-ar">2008-12-24</td>
      <td role="cell">South Delpha</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Reece</td>
      <td role="cell">Langworth</td>
      <td data-value="1101945600000" role="cell" class="epp-ar">2004-12-02</td>
      <td role="cell">Strackeview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Lisandro</td>
      <td role="cell">O'Connell</td>
      <td data-value="-1103932800000" role="cell" class="epp-ar">1935-01-08</td>
      <td role="cell">East Scot</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Kari</td>
      <td role="cell">Zemlak</td>
      <td data-value="664502400000" role="cell" class="epp-ar">1991-01-22</td>
      <td role="cell">Gutmannbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jettie</td>
      <td role="cell">Heaney</td>
      <td data-value="960336000000" role="cell" class="epp-ar">2000-06-07</td>
      <td role="cell">Jacklynport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Raleigh</td>
      <td role="cell">Turner</td>
      <td data-value="633571200000" role="cell" class="epp-ar">1990-01-29</td>
      <td role="cell">Lake Candidohaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Eduardo</td>
      <td role="cell">Gusikowski</td>
      <td data-value="571881600000" role="cell" class="epp-ar">1988-02-15</td>
      <td role="cell">New Crystalbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Bryana</td>
      <td role="cell">Zieme</td>
      <td data-value="744336000000" role="cell" class="epp-ar">1993-08-03</td>
      <td role="cell">Port Jessicatown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Dagmar</td>
      <td role="cell">Hudson</td>
      <td data-value="-345772800000" role="cell" class="epp-ar">1959-01-17</td>
      <td role="cell">Buckchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Elva</td>
      <td role="cell">Koss</td>
      <td data-value="886809600000" role="cell" class="epp-ar">1998-02-07</td>
      <td role="cell">North Ofeliaton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Vergie</td>
      <td role="cell">Cronin</td>
      <td data-value="1104969600000" role="cell" class="epp-ar">2005-01-06</td>
      <td role="cell">Jeramyberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Americo</td>
      <td role="cell">Tillman</td>
      <td data-value="198633600000" role="cell" class="epp-ar">1976-04-18</td>
      <td role="cell">Alleneburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Damaris</td>
      <td role="cell">Hamill</td>
      <td data-value="-151459200000" role="cell" class="epp-ar">1965-03-15</td>
      <td role="cell">North Orlandshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Scot</td>
      <td role="cell">Kris</td>
      <td data-value="1461542400000" role="cell" class="epp-ar">2016-04-25</td>
      <td role="cell">Whiteside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Nasir</td>
      <td role="cell">Ondricka</td>
      <td data-value="919468800000" role="cell" class="epp-ar">1999-02-20</td>
      <td role="cell">Flatleyport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Irwin</td>
      <td role="cell">D'Amore</td>
      <td data-value="-157766400000" role="cell" class="epp-ar">1965-01-01</td>
      <td role="cell">Tobinshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Seamus</td>
      <td role="cell">Blanda</td>
      <td data-value="-1515888000000" role="cell" class="epp-ar">1921-12-19</td>
      <td role="cell">West Mae</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Jeff</td>
      <td role="cell">Murray</td>
      <td data-value="-145238400000" role="cell" class="epp-ar">1965-05-26</td>
      <td role="cell">North Davontechester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Gaetano</td>
      <td role="cell">Lesch</td>
      <td data-value="-157593600000" role="cell" class="epp-ar">1965-01-03</td>
      <td role="cell">South Jedediah</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Aimee</td>
      <td role="cell">Cummings</td>
      <td data-value="-2048457600000" role="cell" class="epp-ar">1905-02-02</td>
      <td role="cell">Rigobertomouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Ivory</td>
      <td role="cell">Medhurst</td>
      <td data-value="-142300800000" role="cell" class="epp-ar">1965-06-29</td>
      <td role="cell">North Colton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Deondre</td>
      <td role="cell">Anderson</td>
      <td data-value="-564537600000" role="cell" class="epp-ar">1952-02-11</td>
      <td role="cell">New Otiliaport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Jimmy</td>
      <td role="cell">Rogahn</td>
      <td data-value="-169603200000" role="cell" class="epp-ar">1964-08-17</td>
      <td role="cell">North Herta</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Mckenzie</td>
      <td role="cell">Goodwin</td>
      <td data-value="-402796800000" role="cell" class="epp-ar">1957-03-28</td>
      <td role="cell">Carolinatown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Sean</td>
      <td role="cell">Hessel</td>
      <td data-value="-703728000000" role="cell" class="epp-ar">1947-09-14</td>
      <td role="cell">South Bobby</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Moriah</td>
      <td role="cell">Mills</td>
      <td data-value="155088000000" role="cell" class="epp-ar">1974-12-01</td>
      <td role="cell">East Ryleighberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Keira</td>
      <td role="cell">Jacobson</td>
      <td data-value="-626313600000" role="cell" class="epp-ar">1950-02-26</td>
      <td role="cell">Lake Rodgertown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Clementina</td>
      <td role="cell">Windler</td>
      <td data-value="-1421625600000" role="cell" class="epp-ar">1924-12-14</td>
      <td role="cell">South Agnesstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Tito</td>
      <td role="cell">Wintheiser</td>
      <td data-value="-1904947200000" role="cell" class="epp-ar">1909-08-21</td>
      <td role="cell">Larsonfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Erwin</td>
      <td role="cell">Batz</td>
      <td data-value="662688000000" role="cell" class="epp-ar">1991-01-01</td>
      <td role="cell">West Courtney</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Keely</td>
      <td role="cell">Lang</td>
      <td data-value="-720403200000" role="cell" class="epp-ar">1947-03-05</td>
      <td role="cell">Lake Murraytown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Alexandrine</td>
      <td role="cell">Kuhic</td>
      <td data-value="1640563200000" role="cell" class="epp-ar">2021-12-27</td>
      <td role="cell">Lake Nils</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Zoey</td>
      <td role="cell">Ruecker</td>
      <td data-value="-141609600000" role="cell" class="epp-ar">1965-07-07</td>
      <td role="cell">Wittingland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Leslie</td>
      <td role="cell">Balistreri</td>
      <td data-value="290304000000" role="cell" class="epp-ar">1979-03-15</td>
      <td role="cell">Edmondville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Carroll</td>
      <td role="cell">Littel</td>
      <td data-value="1598054400000" role="cell" class="epp-ar">2020-08-22</td>
      <td role="cell">Percystad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Thea</td>
      <td role="cell">Stroman</td>
      <td data-value="67564800000" role="cell" class="epp-ar">1972-02-22</td>
      <td role="cell">North Shanashire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Fatima</td>
      <td role="cell">Kunze</td>
      <td data-value="-839462400000" role="cell" class="epp-ar">1943-05-27</td>
      <td role="cell">Port Nicholas</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Laurianne</td>
      <td role="cell">Hauck</td>
      <td data-value="-741484800000" role="cell" class="epp-ar">1946-07-04</td>
      <td role="cell">West Eliborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Kian</td>
      <td role="cell">Zboncak</td>
      <td data-value="1017532800000" role="cell" class="epp-ar">2002-03-31</td>
      <td role="cell">Jerrellside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Adelle</td>
      <td role="cell">Kuhlman</td>
      <td data-value="-615340800000" role="cell" class="epp-ar">1950-07-03</td>
      <td role="cell">New Curtis</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Alfred</td>
      <td role="cell">Towne</td>
      <td data-value="-1242086400000" role="cell" class="epp-ar">1930-08-23</td>
      <td role="cell">Marianneview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Alfreda</td>
      <td role="cell">Hamill</td>
      <td data-value="183600000000" role="cell" class="epp-ar">1975-10-27</td>
      <td role="cell">Valerieside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Corine</td>
      <td role="cell">Johnston</td>
      <td data-value="-92188800000" role="cell" class="epp-ar">1967-01-30</td>
      <td role="cell">Altaberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Marjorie</td>
      <td role="cell">Goyette</td>
      <td data-value="273715200000" role="cell" class="epp-ar">1978-09-04</td>
      <td role="cell">West Corinefort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Sadye</td>
      <td role="cell">Stanton</td>
      <td data-value="1177632000000" role="cell" class="epp-ar">2007-04-27</td>
      <td role="cell">Abbottfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Stewart</td>
      <td role="cell">Schimmel</td>
      <td data-value="-388022400000" role="cell" class="epp-ar">1957-09-15</td>
      <td role="cell">Isidroport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Scarlett</td>
      <td role="cell">Schaden</td>
      <td data-value="-668390400000" role="cell" class="epp-ar">1948-10-27</td>
      <td role="cell">Weberville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Darian</td>
      <td role="cell">Mueller</td>
      <td data-value="-283824000000" role="cell" class="epp-ar">1961-01-03</td>
      <td role="cell">O'Keefeview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Hector</td>
      <td role="cell">Hilpert</td>
      <td data-value="1276905600000" role="cell" class="epp-ar">2010-06-19</td>
      <td role="cell">Skileshaven</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;
}