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
Wales Bartholome Muller 1991-06-28 Lake Adrienne
Scotland Chaya Olson 1965-02-22 East Roderickborough
Northern Ireland Leif Bernhard 2011-03-09 Jensenmouth
Wales Ethel Sawayn 1991-07-23 Eugenebury
Northern Ireland Nickolas Grady 1975-02-20 Gutmannfort
England Lisandro Schimmel 1964-05-30 Hoegerport
England Hilbert Mertz 1957-01-04 Marquardtfort
Wales Loraine Carter 1952-10-08 Lake Nigeltown
Northern Ireland Jude Balistreri 1910-08-31 West Benedictview
Wales Althea Morar 1930-04-21 Willmston
England Paige Wehner 1927-01-08 Gloverstad
Northern Ireland Fletcher Ratke 1930-08-02 East Audieville
England Aaliyah Walsh 2009-04-27 Priceborough
Scotland Constance Jakubowski 1964-08-28 Harveyberg
Northern Ireland Myrtle Walker 2024-08-31 New Edland
Scotland Kevin Price 2016-06-09 South Amya
Scotland Berneice Hagenes 1929-11-21 Jaidaburgh
Wales Myriam Kuhn 1962-07-02 East Jonathan
England Brock Kunde 1985-06-20 Cummingsfurt
Wales Adrienne Schmidt 1982-06-19 Luellashire
England Leilani Swift 1996-10-13 Schmittmouth
Scotland Layla Hane 1950-06-29 New Olafburgh
Northern Ireland Kane Gleason 1904-11-27 Port Gailfort
Scotland Jaylen Schuster 1986-06-13 East Wava
Scotland Kenny Kovacek 2005-11-03 Isaiasstad
Wales Lonnie Hermann 1949-05-01 Krischester
Northern Ireland Jayme Wintheiser 1931-06-17 West Ritastad
England Frankie Rodriguez 1929-03-30 Jastfurt
Wales Javon Ebert 1983-09-04 New Meredith
Scotland Jermey Prosacco 2016-01-17 New Alleneburgh
Scotland Carmela Ryan 1944-04-19 Lavadaburgh
England Mandy Brekke 2008-01-23 Bertramview
Northern Ireland Kiarra Torp 2019-11-29 West Alayna
Scotland Raegan Bradtke 1964-10-29 South Emely
England Elizabeth Ledner 1964-11-06 Marilynemouth
Northern Ireland Lonnie Kuhn 2019-08-08 Abernathyberg
England Godfrey Schuster 1912-07-04 Lizziechester
Scotland Norberto Zemlak 1964-11-02 Reannamouth
England Dayana Franecki 1942-12-21 South Mustafamouth
Wales Clemens Toy 2000-12-16 Angelicafurt
Scotland Lenore Balistreri 1992-01-19 East Fidel
Wales Dayton Leuschke 1925-08-08 West Mathiasmouth
Scotland Katelyn Fritsch 1981-09-12 Port Hilmatown
England Verda Lubowitz 1951-08-12 Gusikowskiberg
England Jaden Bosco 1964-07-28 East Vivianeview
Northern Ireland Shannon Abshire 1965-02-10 North Alexiefort
Northern Ireland Abby Kutch 1974-03-03 West Obie
Scotland Pearl Prohaska 1911-10-12 West Karlee
Northern Ireland Lottie Hickle 1982-06-21 Waylonmouth
Northern Ireland Malachi Lockman 1971-06-10 Connellyton

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">Wales</td>
      <td role="cell">Bartholome</td>
      <td role="cell">Muller</td>
      <td data-value="678067200000" role="cell" class="epp-ar">1991-06-28</td>
      <td role="cell">Lake Adrienne</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Chaya</td>
      <td role="cell">Olson</td>
      <td data-value="-153273600000" role="cell" class="epp-ar">1965-02-22</td>
      <td role="cell">East Roderickborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Leif</td>
      <td role="cell">Bernhard</td>
      <td data-value="1299628800000" role="cell" class="epp-ar">2011-03-09</td>
      <td role="cell">Jensenmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Ethel</td>
      <td role="cell">Sawayn</td>
      <td data-value="680227200000" role="cell" class="epp-ar">1991-07-23</td>
      <td role="cell">Eugenebury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Nickolas</td>
      <td role="cell">Grady</td>
      <td data-value="162086400000" role="cell" class="epp-ar">1975-02-20</td>
      <td role="cell">Gutmannfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Lisandro</td>
      <td role="cell">Schimmel</td>
      <td data-value="-176428800000" role="cell" class="epp-ar">1964-05-30</td>
      <td role="cell">Hoegerport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Hilbert</td>
      <td role="cell">Mertz</td>
      <td data-value="-409968000000" role="cell" class="epp-ar">1957-01-04</td>
      <td role="cell">Marquardtfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Loraine</td>
      <td role="cell">Carter</td>
      <td data-value="-543801600000" role="cell" class="epp-ar">1952-10-08</td>
      <td role="cell">Lake Nigeltown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jude</td>
      <td role="cell">Balistreri</td>
      <td data-value="-1872547200000" role="cell" class="epp-ar">1910-08-31</td>
      <td role="cell">West Benedictview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Althea</td>
      <td role="cell">Morar</td>
      <td data-value="-1252800000000" role="cell" class="epp-ar">1930-04-21</td>
      <td role="cell">Willmston</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Paige</td>
      <td role="cell">Wehner</td>
      <td data-value="-1356393600000" role="cell" class="epp-ar">1927-01-08</td>
      <td role="cell">Gloverstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Fletcher</td>
      <td role="cell">Ratke</td>
      <td data-value="-1243900800000" role="cell" class="epp-ar">1930-08-02</td>
      <td role="cell">East Audieville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Aaliyah</td>
      <td role="cell">Walsh</td>
      <td data-value="1240790400000" role="cell" class="epp-ar">2009-04-27</td>
      <td role="cell">Priceborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Constance</td>
      <td role="cell">Jakubowski</td>
      <td data-value="-168652800000" role="cell" class="epp-ar">1964-08-28</td>
      <td role="cell">Harveyberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Myrtle</td>
      <td role="cell">Walker</td>
      <td data-value="1725062400000" role="cell" class="epp-ar">2024-08-31</td>
      <td role="cell">New Edland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Kevin</td>
      <td role="cell">Price</td>
      <td data-value="1465430400000" role="cell" class="epp-ar">2016-06-09</td>
      <td role="cell">South Amya</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Berneice</td>
      <td role="cell">Hagenes</td>
      <td data-value="-1265846400000" role="cell" class="epp-ar">1929-11-21</td>
      <td role="cell">Jaidaburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Myriam</td>
      <td role="cell">Kuhn</td>
      <td data-value="-236736000000" role="cell" class="epp-ar">1962-07-02</td>
      <td role="cell">East Jonathan</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Brock</td>
      <td role="cell">Kunde</td>
      <td data-value="488073600000" role="cell" class="epp-ar">1985-06-20</td>
      <td role="cell">Cummingsfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Adrienne</td>
      <td role="cell">Schmidt</td>
      <td data-value="393292800000" role="cell" class="epp-ar">1982-06-19</td>
      <td role="cell">Luellashire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Leilani</td>
      <td role="cell">Swift</td>
      <td data-value="845164800000" role="cell" class="epp-ar">1996-10-13</td>
      <td role="cell">Schmittmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Layla</td>
      <td role="cell">Hane</td>
      <td data-value="-615686400000" role="cell" class="epp-ar">1950-06-29</td>
      <td role="cell">New Olafburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Kane</td>
      <td role="cell">Gleason</td>
      <td data-value="-2054246400000" role="cell" class="epp-ar">1904-11-27</td>
      <td role="cell">Port Gailfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jaylen</td>
      <td role="cell">Schuster</td>
      <td data-value="519004800000" role="cell" class="epp-ar">1986-06-13</td>
      <td role="cell">East Wava</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Kenny</td>
      <td role="cell">Kovacek</td>
      <td data-value="1130976000000" role="cell" class="epp-ar">2005-11-03</td>
      <td role="cell">Isaiasstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Lonnie</td>
      <td role="cell">Hermann</td>
      <td data-value="-652320000000" role="cell" class="epp-ar">1949-05-01</td>
      <td role="cell">Krischester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jayme</td>
      <td role="cell">Wintheiser</td>
      <td data-value="-1216339200000" role="cell" class="epp-ar">1931-06-17</td>
      <td role="cell">West Ritastad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Frankie</td>
      <td role="cell">Rodriguez</td>
      <td data-value="-1286236800000" role="cell" class="epp-ar">1929-03-30</td>
      <td role="cell">Jastfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Javon</td>
      <td role="cell">Ebert</td>
      <td data-value="431481600000" role="cell" class="epp-ar">1983-09-04</td>
      <td role="cell">New Meredith</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jermey</td>
      <td role="cell">Prosacco</td>
      <td data-value="1452988800000" role="cell" class="epp-ar">2016-01-17</td>
      <td role="cell">New Alleneburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Carmela</td>
      <td role="cell">Ryan</td>
      <td data-value="-811123200000" role="cell" class="epp-ar">1944-04-19</td>
      <td role="cell">Lavadaburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Mandy</td>
      <td role="cell">Brekke</td>
      <td data-value="1201046400000" role="cell" class="epp-ar">2008-01-23</td>
      <td role="cell">Bertramview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Kiarra</td>
      <td role="cell">Torp</td>
      <td data-value="1574985600000" role="cell" class="epp-ar">2019-11-29</td>
      <td role="cell">West Alayna</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Raegan</td>
      <td role="cell">Bradtke</td>
      <td data-value="-163296000000" role="cell" class="epp-ar">1964-10-29</td>
      <td role="cell">South Emely</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Elizabeth</td>
      <td role="cell">Ledner</td>
      <td data-value="-162604800000" role="cell" class="epp-ar">1964-11-06</td>
      <td role="cell">Marilynemouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Lonnie</td>
      <td role="cell">Kuhn</td>
      <td data-value="1565222400000" role="cell" class="epp-ar">2019-08-08</td>
      <td role="cell">Abernathyberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Godfrey</td>
      <td role="cell">Schuster</td>
      <td data-value="-1814400000000" role="cell" class="epp-ar">1912-07-04</td>
      <td role="cell">Lizziechester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Norberto</td>
      <td role="cell">Zemlak</td>
      <td data-value="-162950400000" role="cell" class="epp-ar">1964-11-02</td>
      <td role="cell">Reannamouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Dayana</td>
      <td role="cell">Franecki</td>
      <td data-value="-853027200000" role="cell" class="epp-ar">1942-12-21</td>
      <td role="cell">South Mustafamouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Clemens</td>
      <td role="cell">Toy</td>
      <td data-value="976924800000" role="cell" class="epp-ar">2000-12-16</td>
      <td role="cell">Angelicafurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Lenore</td>
      <td role="cell">Balistreri</td>
      <td data-value="695779200000" role="cell" class="epp-ar">1992-01-19</td>
      <td role="cell">East Fidel</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Dayton</td>
      <td role="cell">Leuschke</td>
      <td data-value="-1401148800000" role="cell" class="epp-ar">1925-08-08</td>
      <td role="cell">West Mathiasmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Katelyn</td>
      <td role="cell">Fritsch</td>
      <td data-value="369100800000" role="cell" class="epp-ar">1981-09-12</td>
      <td role="cell">Port Hilmatown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Verda</td>
      <td role="cell">Lubowitz</td>
      <td data-value="-580348800000" role="cell" class="epp-ar">1951-08-12</td>
      <td role="cell">Gusikowskiberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Jaden</td>
      <td role="cell">Bosco</td>
      <td data-value="-171331200000" role="cell" class="epp-ar">1964-07-28</td>
      <td role="cell">East Vivianeview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Shannon</td>
      <td role="cell">Abshire</td>
      <td data-value="-154310400000" role="cell" class="epp-ar">1965-02-10</td>
      <td role="cell">North Alexiefort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Abby</td>
      <td role="cell">Kutch</td>
      <td data-value="131500800000" role="cell" class="epp-ar">1974-03-03</td>
      <td role="cell">West Obie</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Pearl</td>
      <td role="cell">Prohaska</td>
      <td data-value="-1837382400000" role="cell" class="epp-ar">1911-10-12</td>
      <td role="cell">West Karlee</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Lottie</td>
      <td role="cell">Hickle</td>
      <td data-value="393465600000" role="cell" class="epp-ar">1982-06-21</td>
      <td role="cell">Waylonmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Malachi</td>
      <td role="cell">Lockman</td>
      <td data-value="45360000000" role="cell" class="epp-ar">1971-06-10</td>
      <td role="cell">Connellyton</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;
}