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 Keara Terry 2002-11-26 Amirburgh
England Santiago Parisian 1963-09-03 North Roslyn
Northern Ireland Leann Dietrich 1963-06-21 North Brenda
Scotland Rudy Goldner 1923-05-10 Ebonyville
England Valerie Kemmer 1920-01-22 Amelieside
Wales Hipolito Bruen 1996-07-15 East Jamison
Northern Ireland Darryl Bahringer 1977-07-08 Lake Astridville
Wales Colleen Wilderman 2002-02-23 North Garrisontown
Northern Ireland Jimmy Windler 1931-05-11 Christaburgh
Wales Cory Collins 1987-02-04 Port Laronville
Scotland Vern McCullough 1935-04-07 New Itzel
Northern Ireland Marjolaine Abbott 2010-01-05 Hettingerstad
Wales Branson Spinka 1951-11-24 Gladyschester
Northern Ireland Jazlyn Roberts 1944-02-24 North Maximeview
Scotland Jerrell Volkman 1967-05-12 West Fiona
England Beth Baumbach 1962-12-09 Gloverberg
Northern Ireland Alfredo Kemmer 2017-01-25 Armstrongville
Wales Eula Wiza 2000-10-18 Lake Aliburgh
Wales Kiel Hickle 1958-01-28 Lake Minnie
Scotland Sage Zemlak 1991-01-28 Lake Arvel
Scotland Raul Mann 1978-05-06 North Sheilaport
Northern Ireland Torey Quigley 1984-05-06 North Rodside
England Hobart Hauck 1990-11-28 Elmirahaven
Wales Keagan Willms 1998-05-10 Misaelton
England Margret Hessel 1940-06-12 Port Ernie
England Monique Bartell 1944-09-22 Lake Madalineview
Wales Jaida Rosenbaum 2021-09-04 Port Floyton
Scotland Crystel Durgan 1929-02-20 Lake Herminiaberg
Scotland Lance Farrell 1991-05-27 Cliftonhaven
England Andres Kihn 2010-06-30 Dannieville
Northern Ireland Jessie Purdy 1963-08-05 Eloychester
Northern Ireland Matilda Batz 1967-05-27 Port Randall
Northern Ireland Maybelle Little 1964-01-03 Steuberborough
Wales Rosina Nienow 2012-12-26 New Geovanny
Northern Ireland Orland Hickle 1969-07-13 North Antwanfort
Northern Ireland Maureen Gusikowski 1967-08-26 New Dorthychester
England Laila Kunde 2008-04-14 South Benniemouth
Scotland Kiel D'Amore 1990-04-24 Ellieburgh
England Marcelo Koepp 2005-06-24 Rethaland
Scotland Colten Nikolaus 1969-07-28 South Edgardomouth
Wales June Pouros 1940-01-10 West Randi
Northern Ireland Vernie Schmitt 2004-05-09 East Deshawnfort
Northern Ireland Evert McLaughlin 1963-02-23 North Bradly
Wales Payton Bauch 1965-04-23 North Horaciobury
Northern Ireland Jeanette Hamill 1967-07-01 Bergechester
England Zita McKenzie 1981-10-01 Dickenshaven
England Dewitt Parker 1950-10-15 Reinholdtown
England Murl Skiles 1938-04-20 East Braxtonstad
Northern Ireland Trevor Parisian 1963-07-13 Sengerfurt
Scotland Charlie Rath 1951-05-08 South Pietrofort

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">Keara</td>
      <td role="cell">Terry</td>
      <td data-value="1038268800000" role="cell" class="epp-ar">2002-11-26</td>
      <td role="cell">Amirburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Santiago</td>
      <td role="cell">Parisian</td>
      <td data-value="-199756800000" role="cell" class="epp-ar">1963-09-03</td>
      <td role="cell">North Roslyn</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Leann</td>
      <td role="cell">Dietrich</td>
      <td data-value="-206150400000" role="cell" class="epp-ar">1963-06-21</td>
      <td role="cell">North Brenda</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Rudy</td>
      <td role="cell">Goldner</td>
      <td data-value="-1472083200000" role="cell" class="epp-ar">1923-05-10</td>
      <td role="cell">Ebonyville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Valerie</td>
      <td role="cell">Kemmer</td>
      <td data-value="-1576108800000" role="cell" class="epp-ar">1920-01-22</td>
      <td role="cell">Amelieside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Hipolito</td>
      <td role="cell">Bruen</td>
      <td data-value="837388800000" role="cell" class="epp-ar">1996-07-15</td>
      <td role="cell">East Jamison</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Darryl</td>
      <td role="cell">Bahringer</td>
      <td data-value="237168000000" role="cell" class="epp-ar">1977-07-08</td>
      <td role="cell">Lake Astridville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Colleen</td>
      <td role="cell">Wilderman</td>
      <td data-value="1014422400000" role="cell" class="epp-ar">2002-02-23</td>
      <td role="cell">North Garrisontown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jimmy</td>
      <td role="cell">Windler</td>
      <td data-value="-1219536000000" role="cell" class="epp-ar">1931-05-11</td>
      <td role="cell">Christaburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Cory</td>
      <td role="cell">Collins</td>
      <td data-value="539395200000" role="cell" class="epp-ar">1987-02-04</td>
      <td role="cell">Port Laronville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Vern</td>
      <td role="cell">McCullough</td>
      <td data-value="-1096243200000" role="cell" class="epp-ar">1935-04-07</td>
      <td role="cell">New Itzel</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Marjolaine</td>
      <td role="cell">Abbott</td>
      <td data-value="1262649600000" role="cell" class="epp-ar">2010-01-05</td>
      <td role="cell">Hettingerstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Branson</td>
      <td role="cell">Spinka</td>
      <td data-value="-571363200000" role="cell" class="epp-ar">1951-11-24</td>
      <td role="cell">Gladyschester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jazlyn</td>
      <td role="cell">Roberts</td>
      <td data-value="-815875200000" role="cell" class="epp-ar">1944-02-24</td>
      <td role="cell">North Maximeview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jerrell</td>
      <td role="cell">Volkman</td>
      <td data-value="-83376000000" role="cell" class="epp-ar">1967-05-12</td>
      <td role="cell">West Fiona</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Beth</td>
      <td role="cell">Baumbach</td>
      <td data-value="-222912000000" role="cell" class="epp-ar">1962-12-09</td>
      <td role="cell">Gloverberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Alfredo</td>
      <td role="cell">Kemmer</td>
      <td data-value="1485302400000" role="cell" class="epp-ar">2017-01-25</td>
      <td role="cell">Armstrongville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Eula</td>
      <td role="cell">Wiza</td>
      <td data-value="971827200000" role="cell" class="epp-ar">2000-10-18</td>
      <td role="cell">Lake Aliburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Kiel</td>
      <td role="cell">Hickle</td>
      <td data-value="-376358400000" role="cell" class="epp-ar">1958-01-28</td>
      <td role="cell">Lake Minnie</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Sage</td>
      <td role="cell">Zemlak</td>
      <td data-value="665020800000" role="cell" class="epp-ar">1991-01-28</td>
      <td role="cell">Lake Arvel</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Raul</td>
      <td role="cell">Mann</td>
      <td data-value="263260800000" role="cell" class="epp-ar">1978-05-06</td>
      <td role="cell">North Sheilaport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Torey</td>
      <td role="cell">Quigley</td>
      <td data-value="452649600000" role="cell" class="epp-ar">1984-05-06</td>
      <td role="cell">North Rodside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Hobart</td>
      <td role="cell">Hauck</td>
      <td data-value="659750400000" role="cell" class="epp-ar">1990-11-28</td>
      <td role="cell">Elmirahaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Keagan</td>
      <td role="cell">Willms</td>
      <td data-value="894758400000" role="cell" class="epp-ar">1998-05-10</td>
      <td role="cell">Misaelton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Margret</td>
      <td role="cell">Hessel</td>
      <td data-value="-932688000000" role="cell" class="epp-ar">1940-06-12</td>
      <td role="cell">Port Ernie</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Monique</td>
      <td role="cell">Bartell</td>
      <td data-value="-797644800000" role="cell" class="epp-ar">1944-09-22</td>
      <td role="cell">Lake Madalineview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Jaida</td>
      <td role="cell">Rosenbaum</td>
      <td data-value="1630713600000" role="cell" class="epp-ar">2021-09-04</td>
      <td role="cell">Port Floyton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Crystel</td>
      <td role="cell">Durgan</td>
      <td data-value="-1289520000000" role="cell" class="epp-ar">1929-02-20</td>
      <td role="cell">Lake Herminiaberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Lance</td>
      <td role="cell">Farrell</td>
      <td data-value="675302400000" role="cell" class="epp-ar">1991-05-27</td>
      <td role="cell">Cliftonhaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Andres</td>
      <td role="cell">Kihn</td>
      <td data-value="1277856000000" role="cell" class="epp-ar">2010-06-30</td>
      <td role="cell">Dannieville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jessie</td>
      <td role="cell">Purdy</td>
      <td data-value="-202262400000" role="cell" class="epp-ar">1963-08-05</td>
      <td role="cell">Eloychester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Matilda</td>
      <td role="cell">Batz</td>
      <td data-value="-82080000000" role="cell" class="epp-ar">1967-05-27</td>
      <td role="cell">Port Randall</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Maybelle</td>
      <td role="cell">Little</td>
      <td data-value="-189216000000" role="cell" class="epp-ar">1964-01-03</td>
      <td role="cell">Steuberborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Rosina</td>
      <td role="cell">Nienow</td>
      <td data-value="1356480000000" role="cell" class="epp-ar">2012-12-26</td>
      <td role="cell">New Geovanny</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Orland</td>
      <td role="cell">Hickle</td>
      <td data-value="-14860800000" role="cell" class="epp-ar">1969-07-13</td>
      <td role="cell">North Antwanfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Maureen</td>
      <td role="cell">Gusikowski</td>
      <td data-value="-74217600000" role="cell" class="epp-ar">1967-08-26</td>
      <td role="cell">New Dorthychester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Laila</td>
      <td role="cell">Kunde</td>
      <td data-value="1208131200000" role="cell" class="epp-ar">2008-04-14</td>
      <td role="cell">South Benniemouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Kiel</td>
      <td role="cell">D'Amore</td>
      <td data-value="640915200000" role="cell" class="epp-ar">1990-04-24</td>
      <td role="cell">Ellieburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Marcelo</td>
      <td role="cell">Koepp</td>
      <td data-value="1119571200000" role="cell" class="epp-ar">2005-06-24</td>
      <td role="cell">Rethaland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Colten</td>
      <td role="cell">Nikolaus</td>
      <td data-value="-13564800000" role="cell" class="epp-ar">1969-07-28</td>
      <td role="cell">South Edgardomouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">June</td>
      <td role="cell">Pouros</td>
      <td data-value="-945993600000" role="cell" class="epp-ar">1940-01-10</td>
      <td role="cell">West Randi</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Vernie</td>
      <td role="cell">Schmitt</td>
      <td data-value="1084060800000" role="cell" class="epp-ar">2004-05-09</td>
      <td role="cell">East Deshawnfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Evert</td>
      <td role="cell">McLaughlin</td>
      <td data-value="-216345600000" role="cell" class="epp-ar">1963-02-23</td>
      <td role="cell">North Bradly</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Payton</td>
      <td role="cell">Bauch</td>
      <td data-value="-148089600000" role="cell" class="epp-ar">1965-04-23</td>
      <td role="cell">North Horaciobury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jeanette</td>
      <td role="cell">Hamill</td>
      <td data-value="-79056000000" role="cell" class="epp-ar">1967-07-01</td>
      <td role="cell">Bergechester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Zita</td>
      <td role="cell">McKenzie</td>
      <td data-value="370742400000" role="cell" class="epp-ar">1981-10-01</td>
      <td role="cell">Dickenshaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Dewitt</td>
      <td role="cell">Parker</td>
      <td data-value="-606355200000" role="cell" class="epp-ar">1950-10-15</td>
      <td role="cell">Reinholdtown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Murl</td>
      <td role="cell">Skiles</td>
      <td data-value="-1000425600000" role="cell" class="epp-ar">1938-04-20</td>
      <td role="cell">East Braxtonstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Trevor</td>
      <td role="cell">Parisian</td>
      <td data-value="-204249600000" role="cell" class="epp-ar">1963-07-13</td>
      <td role="cell">Sengerfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Charlie</td>
      <td role="cell">Rath</td>
      <td data-value="-588643200000" role="cell" class="epp-ar">1951-05-08</td>
      <td role="cell">South Pietrofort</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;
}