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 Gabriella Ebert 1964-11-02 West Stephonmouth
England Monserrat Lowe 1965-01-10 Port Lennymouth
Scotland Maybell Mitchell 1990-11-14 Lilianfurt
Scotland Aron Shanahan 1928-05-29 Okunevaside
Northern Ireland Alessia Leannon 1950-05-13 South Destinhaven
Wales Hollis Murazik 1943-06-02 Shieldsfurt
England Vanessa Weissnat 1933-06-17 Lake Jewelborough
Wales Leif Ebert 1965-02-26 North Leopoldoside
Wales Jarret Emmerich 1972-04-13 Keeblershire
Wales Lew Watsica 1971-10-22 North Colby
Scotland Annabel Kemmer 1931-09-09 Kaiafort
Northern Ireland Rosemary Lindgren 1965-09-26 South Adelia
Wales Shaun Blick 1961-04-08 Elinoreview
Northern Ireland Destiny Runolfsdottir 1924-04-05 Connellymouth
Northern Ireland Cullen Boyle 1904-07-05 Henrifurt
Wales Kendrick VonRueden 1912-12-06 New Uriel
England Jesus Parker 1939-09-11 New Marilou
Northern Ireland Connie Von 2002-10-08 Colliertown
England Cheyenne Jast 1908-04-09 North Freemanbury
England Geovanny Nienow 1942-07-21 Framiville
Scotland Jamal Funk 1972-11-30 South Madelynberg
Scotland Rozella Kilback 1989-07-06 Sophialand
Scotland Angeline Trantow 1944-03-25 East Elvisview
Scotland Shyanne Stamm 1947-04-29 New Casimerborough
Northern Ireland Bailee DuBuque 1950-06-25 East Janborough
England Mekhi Bins 1988-01-11 Dangelotown
England Leonardo Heaney 1905-06-08 East Damonport
Northern Ireland Mabel Heidenreich 1958-07-02 Orenchester
England Kevin Kovacek 1961-10-30 West Alfonso
Scotland Euna Williamson 2008-06-28 Hackettbury
Northern Ireland Reilly Boehm 1925-03-19 South Karleeside
Wales Kayden Bergstrom 1955-10-29 Bonitastad
Wales Marcel Heller 1989-04-20 North Levi
Scotland Madelynn Littel 1989-08-18 Swiftport
England Eden D'Amore 1924-02-17 South Williamberg
Wales Elouise Adams 1962-09-30 East Fabiolaborough
England Rashawn Homenick 1965-06-22 Noemiemouth
England Aditya Leffler 1921-09-17 Trefort
Wales Kimberly Jast 1967-04-04 West Maria
Scotland Wellington DuBuque 2011-06-27 Kiannaland
Wales Hyman Stehr 1919-06-19 Rickeychester
Northern Ireland Virgie Douglas 1904-01-20 Port Omer
England Ivory Witting 2002-06-22 Richardton
Scotland Sonny Gottlieb 1915-09-22 Breanaborough
England Seamus Langosh 1957-01-26 Bauchmouth
Wales Maverick Wilkinson 1932-04-15 West Allene
Scotland Demond O'Keefe 1951-03-01 South Kadinport
England Norene Stark 1917-06-10 Rempelmouth
Northern Ireland Phyllis Wuckert 1933-12-28 South Jettieborough
Scotland Jermey Champlin 1984-10-25 East Geo

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">Gabriella</td>
      <td role="cell">Ebert</td>
      <td data-value="-162950400000" role="cell" class="epp-ar">1964-11-02</td>
      <td role="cell">West Stephonmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Monserrat</td>
      <td role="cell">Lowe</td>
      <td data-value="-156988800000" role="cell" class="epp-ar">1965-01-10</td>
      <td role="cell">Port Lennymouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Maybell</td>
      <td role="cell">Mitchell</td>
      <td data-value="658540800000" role="cell" class="epp-ar">1990-11-14</td>
      <td role="cell">Lilianfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Aron</td>
      <td role="cell">Shanahan</td>
      <td data-value="-1312588800000" role="cell" class="epp-ar">1928-05-29</td>
      <td role="cell">Okunevaside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Alessia</td>
      <td role="cell">Leannon</td>
      <td data-value="-619747200000" role="cell" class="epp-ar">1950-05-13</td>
      <td role="cell">South Destinhaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Hollis</td>
      <td role="cell">Murazik</td>
      <td data-value="-838944000000" role="cell" class="epp-ar">1943-06-02</td>
      <td role="cell">Shieldsfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Vanessa</td>
      <td role="cell">Weissnat</td>
      <td data-value="-1153180800000" role="cell" class="epp-ar">1933-06-17</td>
      <td role="cell">Lake Jewelborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Leif</td>
      <td role="cell">Ebert</td>
      <td data-value="-152928000000" role="cell" class="epp-ar">1965-02-26</td>
      <td role="cell">North Leopoldoside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Jarret</td>
      <td role="cell">Emmerich</td>
      <td data-value="71971200000" role="cell" class="epp-ar">1972-04-13</td>
      <td role="cell">Keeblershire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Lew</td>
      <td role="cell">Watsica</td>
      <td data-value="56937600000" role="cell" class="epp-ar">1971-10-22</td>
      <td role="cell">North Colby</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Annabel</td>
      <td role="cell">Kemmer</td>
      <td data-value="-1209081600000" role="cell" class="epp-ar">1931-09-09</td>
      <td role="cell">Kaiafort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Rosemary</td>
      <td role="cell">Lindgren</td>
      <td data-value="-134611200000" role="cell" class="epp-ar">1965-09-26</td>
      <td role="cell">South Adelia</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Shaun</td>
      <td role="cell">Blick</td>
      <td data-value="-275616000000" role="cell" class="epp-ar">1961-04-08</td>
      <td role="cell">Elinoreview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Destiny</td>
      <td role="cell">Runolfsdottir</td>
      <td data-value="-1443484800000" role="cell" class="epp-ar">1924-04-05</td>
      <td role="cell">Connellymouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Cullen</td>
      <td role="cell">Boyle</td>
      <td data-value="-2066774400000" role="cell" class="epp-ar">1904-07-05</td>
      <td role="cell">Henrifurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Kendrick</td>
      <td role="cell">VonRueden</td>
      <td data-value="-1801008000000" role="cell" class="epp-ar">1912-12-06</td>
      <td role="cell">New Uriel</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Jesus</td>
      <td role="cell">Parker</td>
      <td data-value="-956448000000" role="cell" class="epp-ar">1939-09-11</td>
      <td role="cell">New Marilou</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Connie</td>
      <td role="cell">Von</td>
      <td data-value="1034035200000" role="cell" class="epp-ar">2002-10-08</td>
      <td role="cell">Colliertown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Cheyenne</td>
      <td role="cell">Jast</td>
      <td data-value="-1948060800000" role="cell" class="epp-ar">1908-04-09</td>
      <td role="cell">North Freemanbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Geovanny</td>
      <td role="cell">Nienow</td>
      <td data-value="-866246400000" role="cell" class="epp-ar">1942-07-21</td>
      <td role="cell">Framiville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jamal</td>
      <td role="cell">Funk</td>
      <td data-value="91929600000" role="cell" class="epp-ar">1972-11-30</td>
      <td role="cell">South Madelynberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Rozella</td>
      <td role="cell">Kilback</td>
      <td data-value="615686400000" role="cell" class="epp-ar">1989-07-06</td>
      <td role="cell">Sophialand</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Angeline</td>
      <td role="cell">Trantow</td>
      <td data-value="-813283200000" role="cell" class="epp-ar">1944-03-25</td>
      <td role="cell">East Elvisview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Shyanne</td>
      <td role="cell">Stamm</td>
      <td data-value="-715651200000" role="cell" class="epp-ar">1947-04-29</td>
      <td role="cell">New Casimerborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Bailee</td>
      <td role="cell">DuBuque</td>
      <td data-value="-616032000000" role="cell" class="epp-ar">1950-06-25</td>
      <td role="cell">East Janborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Mekhi</td>
      <td role="cell">Bins</td>
      <td data-value="568857600000" role="cell" class="epp-ar">1988-01-11</td>
      <td role="cell">Dangelotown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Leonardo</td>
      <td role="cell">Heaney</td>
      <td data-value="-2037571200000" role="cell" class="epp-ar">1905-06-08</td>
      <td role="cell">East Damonport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Mabel</td>
      <td role="cell">Heidenreich</td>
      <td data-value="-362966400000" role="cell" class="epp-ar">1958-07-02</td>
      <td role="cell">Orenchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Kevin</td>
      <td role="cell">Kovacek</td>
      <td data-value="-257904000000" role="cell" class="epp-ar">1961-10-30</td>
      <td role="cell">West Alfonso</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Euna</td>
      <td role="cell">Williamson</td>
      <td data-value="1214611200000" role="cell" class="epp-ar">2008-06-28</td>
      <td role="cell">Hackettbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Reilly</td>
      <td role="cell">Boehm</td>
      <td data-value="-1413417600000" role="cell" class="epp-ar">1925-03-19</td>
      <td role="cell">South Karleeside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Kayden</td>
      <td role="cell">Bergstrom</td>
      <td data-value="-447379200000" role="cell" class="epp-ar">1955-10-29</td>
      <td role="cell">Bonitastad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Marcel</td>
      <td role="cell">Heller</td>
      <td data-value="609033600000" role="cell" class="epp-ar">1989-04-20</td>
      <td role="cell">North Levi</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Madelynn</td>
      <td role="cell">Littel</td>
      <td data-value="619401600000" role="cell" class="epp-ar">1989-08-18</td>
      <td role="cell">Swiftport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Eden</td>
      <td role="cell">D'Amore</td>
      <td data-value="-1447632000000" role="cell" class="epp-ar">1924-02-17</td>
      <td role="cell">South Williamberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Elouise</td>
      <td role="cell">Adams</td>
      <td data-value="-228960000000" role="cell" class="epp-ar">1962-09-30</td>
      <td role="cell">East Fabiolaborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Rashawn</td>
      <td role="cell">Homenick</td>
      <td data-value="-142905600000" role="cell" class="epp-ar">1965-06-22</td>
      <td role="cell">Noemiemouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Aditya</td>
      <td role="cell">Leffler</td>
      <td data-value="-1523923200000" role="cell" class="epp-ar">1921-09-17</td>
      <td role="cell">Trefort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Kimberly</td>
      <td role="cell">Jast</td>
      <td data-value="-86659200000" role="cell" class="epp-ar">1967-04-04</td>
      <td role="cell">West Maria</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Wellington</td>
      <td role="cell">DuBuque</td>
      <td data-value="1309132800000" role="cell" class="epp-ar">2011-06-27</td>
      <td role="cell">Kiannaland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Hyman</td>
      <td role="cell">Stehr</td>
      <td data-value="-1594857600000" role="cell" class="epp-ar">1919-06-19</td>
      <td role="cell">Rickeychester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Virgie</td>
      <td role="cell">Douglas</td>
      <td data-value="-2081203200000" role="cell" class="epp-ar">1904-01-20</td>
      <td role="cell">Port Omer</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Ivory</td>
      <td role="cell">Witting</td>
      <td data-value="1024704000000" role="cell" class="epp-ar">2002-06-22</td>
      <td role="cell">Richardton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Sonny</td>
      <td role="cell">Gottlieb</td>
      <td data-value="-1712880000000" role="cell" class="epp-ar">1915-09-22</td>
      <td role="cell">Breanaborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Seamus</td>
      <td role="cell">Langosh</td>
      <td data-value="-408067200000" role="cell" class="epp-ar">1957-01-26</td>
      <td role="cell">Bauchmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Maverick</td>
      <td role="cell">Wilkinson</td>
      <td data-value="-1190160000000" role="cell" class="epp-ar">1932-04-15</td>
      <td role="cell">West Allene</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Demond</td>
      <td role="cell">O'Keefe</td>
      <td data-value="-594518400000" role="cell" class="epp-ar">1951-03-01</td>
      <td role="cell">South Kadinport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Norene</td>
      <td role="cell">Stark</td>
      <td data-value="-1658707200000" role="cell" class="epp-ar">1917-06-10</td>
      <td role="cell">Rempelmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Phyllis</td>
      <td role="cell">Wuckert</td>
      <td data-value="-1136419200000" role="cell" class="epp-ar">1933-12-28</td>
      <td role="cell">South Jettieborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jermey</td>
      <td role="cell">Champlin</td>
      <td data-value="467510400000" role="cell" class="epp-ar">1984-10-25</td>
      <td role="cell">East Geo</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;
}