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 Freda Botsford 1997-12-16 West Emmanueltown
Northern Ireland King Champlin 1951-12-03 South Jaymemouth
Wales Philip Braun 1908-12-20 East Jayme
England Carleton Wunsch 1975-10-20 Camdenfurt
Northern Ireland Janie Dibbert 1965-01-09 West Cindy
Northern Ireland Joelle Bartoletti 1948-05-08 South Casperchester
Northern Ireland Velda Runte 1969-03-09 Sawaynstad
England Moises Hansen 1938-02-26 North Cayla
Scotland Cletus Abernathy 1964-04-11 West Dayna
Scotland Guido Fritsch 1934-01-08 Strosinberg
Northern Ireland Jalon Kunze 1966-04-15 Lake Dawntown
England Daisy Predovic 1953-02-23 East Rebeka
England Deja Parisian 1964-11-24 Danikamouth
Wales Alec Boehm 1930-04-19 Reingerchester
Northern Ireland Jane Bode 1985-11-22 North Jany
Northern Ireland Dameon Brekke 1951-11-01 East Claudineborough
England Aubree Johns 1960-12-12 Port Amaliamouth
Wales Agustina Renner 1948-07-09 Lake Miles
Northern Ireland Jameson Abshire 2020-01-17 Lake Elsie
Wales Ali Wisoky 1955-01-14 South Carrollburgh
Scotland Jalyn Langworth 1992-11-26 Hudsonburgh
England Cleve Treutel 2005-04-15 North Rahul
Scotland Rebekah Reinger 1919-12-09 Robertsfurt
Wales Oren Mante 1971-06-21 South Kenyonbury
England Stewart Marvin 1950-09-25 West Hettie
Scotland Demetrius Herman 1996-07-25 Townefurt
Wales Joaquin Doyle 1957-03-15 South Brandt
Scotland Eldon Effertz 1932-04-16 East Evangelinefurt
England Queenie Gusikowski 1964-09-09 DuBuquemouth
Scotland Baylee Kessler 1964-01-18 Runolfssonshire
Wales Cristobal Bernhard 2020-06-06 South Blancaland
Scotland Arjun Smith 1965-03-29 East Cordieland
Wales Al Hintz 2013-09-16 Olsonbury
Scotland Anya Conn 1964-09-11 Nannieton
England Scotty Zboncak 2002-08-16 Port Geovanyborough
Wales Margarette Gottlieb 1964-10-06 West Lesleyhaven
Northern Ireland Daniela Runte 1956-09-17 East Jaylinport
England Hunter Mraz 2000-08-17 Simonisberg
Northern Ireland Webster Toy 1965-03-31 Natashamouth
Scotland Layla Ondricka 1933-09-12 Aureliaton
Northern Ireland Branson Shields 2009-09-15 New Manuela
Northern Ireland Camryn Von 1985-05-20 North Auroreshire
Scotland Mya Buckridge 1917-08-25 Zoraborough
England Keira Torp 2024-11-19 Medhurstshire
Scotland Edythe Ferry 1905-06-07 East Micaela
Scotland Zetta Gleichner 2011-07-27 Lake Lou
Northern Ireland Barton Fisher 1959-12-18 South Connieview
Scotland Reta Lemke 2007-06-11 West Juvenal
Wales Burdette Bayer 1904-12-12 Lake Eleanoraburgh
Northern Ireland Kameron Marks 1922-12-04 North Ahmadtown

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">Freda</td>
      <td role="cell">Botsford</td>
      <td data-value="882230400000" role="cell" class="epp-ar">1997-12-16</td>
      <td role="cell">West Emmanueltown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">King</td>
      <td role="cell">Champlin</td>
      <td data-value="-570585600000" role="cell" class="epp-ar">1951-12-03</td>
      <td role="cell">South Jaymemouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Philip</td>
      <td role="cell">Braun</td>
      <td data-value="-1926028800000" role="cell" class="epp-ar">1908-12-20</td>
      <td role="cell">East Jayme</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Carleton</td>
      <td role="cell">Wunsch</td>
      <td data-value="182995200000" role="cell" class="epp-ar">1975-10-20</td>
      <td role="cell">Camdenfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Janie</td>
      <td role="cell">Dibbert</td>
      <td data-value="-157075200000" role="cell" class="epp-ar">1965-01-09</td>
      <td role="cell">West Cindy</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Joelle</td>
      <td role="cell">Bartoletti</td>
      <td data-value="-683251200000" role="cell" class="epp-ar">1948-05-08</td>
      <td role="cell">South Casperchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Velda</td>
      <td role="cell">Runte</td>
      <td data-value="-25747200000" role="cell" class="epp-ar">1969-03-09</td>
      <td role="cell">Sawaynstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Moises</td>
      <td role="cell">Hansen</td>
      <td data-value="-1005004800000" role="cell" class="epp-ar">1938-02-26</td>
      <td role="cell">North Cayla</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Cletus</td>
      <td role="cell">Abernathy</td>
      <td data-value="-180662400000" role="cell" class="epp-ar">1964-04-11</td>
      <td role="cell">West Dayna</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Guido</td>
      <td role="cell">Fritsch</td>
      <td data-value="-1135468800000" role="cell" class="epp-ar">1934-01-08</td>
      <td role="cell">Strosinberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jalon</td>
      <td role="cell">Kunze</td>
      <td data-value="-117244800000" role="cell" class="epp-ar">1966-04-15</td>
      <td role="cell">Lake Dawntown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Daisy</td>
      <td role="cell">Predovic</td>
      <td data-value="-531878400000" role="cell" class="epp-ar">1953-02-23</td>
      <td role="cell">East Rebeka</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Deja</td>
      <td role="cell">Parisian</td>
      <td data-value="-161049600000" role="cell" class="epp-ar">1964-11-24</td>
      <td role="cell">Danikamouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Alec</td>
      <td role="cell">Boehm</td>
      <td data-value="-1252972800000" role="cell" class="epp-ar">1930-04-19</td>
      <td role="cell">Reingerchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jane</td>
      <td role="cell">Bode</td>
      <td data-value="501465600000" role="cell" class="epp-ar">1985-11-22</td>
      <td role="cell">North Jany</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Dameon</td>
      <td role="cell">Brekke</td>
      <td data-value="-573350400000" role="cell" class="epp-ar">1951-11-01</td>
      <td role="cell">East Claudineborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Aubree</td>
      <td role="cell">Johns</td>
      <td data-value="-285724800000" role="cell" class="epp-ar">1960-12-12</td>
      <td role="cell">Port Amaliamouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Agustina</td>
      <td role="cell">Renner</td>
      <td data-value="-677894400000" role="cell" class="epp-ar">1948-07-09</td>
      <td role="cell">Lake Miles</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jameson</td>
      <td role="cell">Abshire</td>
      <td data-value="1579219200000" role="cell" class="epp-ar">2020-01-17</td>
      <td role="cell">Lake Elsie</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Ali</td>
      <td role="cell">Wisoky</td>
      <td data-value="-472262400000" role="cell" class="epp-ar">1955-01-14</td>
      <td role="cell">South Carrollburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jalyn</td>
      <td role="cell">Langworth</td>
      <td data-value="722736000000" role="cell" class="epp-ar">1992-11-26</td>
      <td role="cell">Hudsonburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Cleve</td>
      <td role="cell">Treutel</td>
      <td data-value="1113523200000" role="cell" class="epp-ar">2005-04-15</td>
      <td role="cell">North Rahul</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Rebekah</td>
      <td role="cell">Reinger</td>
      <td data-value="-1579910400000" role="cell" class="epp-ar">1919-12-09</td>
      <td role="cell">Robertsfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Oren</td>
      <td role="cell">Mante</td>
      <td data-value="46310400000" role="cell" class="epp-ar">1971-06-21</td>
      <td role="cell">South Kenyonbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Stewart</td>
      <td role="cell">Marvin</td>
      <td data-value="-608083200000" role="cell" class="epp-ar">1950-09-25</td>
      <td role="cell">West Hettie</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Demetrius</td>
      <td role="cell">Herman</td>
      <td data-value="838252800000" role="cell" class="epp-ar">1996-07-25</td>
      <td role="cell">Townefurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Joaquin</td>
      <td role="cell">Doyle</td>
      <td data-value="-403920000000" role="cell" class="epp-ar">1957-03-15</td>
      <td role="cell">South Brandt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Eldon</td>
      <td role="cell">Effertz</td>
      <td data-value="-1190073600000" role="cell" class="epp-ar">1932-04-16</td>
      <td role="cell">East Evangelinefurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Queenie</td>
      <td role="cell">Gusikowski</td>
      <td data-value="-167616000000" role="cell" class="epp-ar">1964-09-09</td>
      <td role="cell">DuBuquemouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Baylee</td>
      <td role="cell">Kessler</td>
      <td data-value="-187920000000" role="cell" class="epp-ar">1964-01-18</td>
      <td role="cell">Runolfssonshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Cristobal</td>
      <td role="cell">Bernhard</td>
      <td data-value="1591401600000" role="cell" class="epp-ar">2020-06-06</td>
      <td role="cell">South Blancaland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Arjun</td>
      <td role="cell">Smith</td>
      <td data-value="-150249600000" role="cell" class="epp-ar">1965-03-29</td>
      <td role="cell">East Cordieland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Al</td>
      <td role="cell">Hintz</td>
      <td data-value="1379289600000" role="cell" class="epp-ar">2013-09-16</td>
      <td role="cell">Olsonbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Anya</td>
      <td role="cell">Conn</td>
      <td data-value="-167443200000" role="cell" class="epp-ar">1964-09-11</td>
      <td role="cell">Nannieton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Scotty</td>
      <td role="cell">Zboncak</td>
      <td data-value="1029456000000" role="cell" class="epp-ar">2002-08-16</td>
      <td role="cell">Port Geovanyborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Margarette</td>
      <td role="cell">Gottlieb</td>
      <td data-value="-165283200000" role="cell" class="epp-ar">1964-10-06</td>
      <td role="cell">West Lesleyhaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Daniela</td>
      <td role="cell">Runte</td>
      <td data-value="-419385600000" role="cell" class="epp-ar">1956-09-17</td>
      <td role="cell">East Jaylinport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Hunter</td>
      <td role="cell">Mraz</td>
      <td data-value="966470400000" role="cell" class="epp-ar">2000-08-17</td>
      <td role="cell">Simonisberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Webster</td>
      <td role="cell">Toy</td>
      <td data-value="-150076800000" role="cell" class="epp-ar">1965-03-31</td>
      <td role="cell">Natashamouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Layla</td>
      <td role="cell">Ondricka</td>
      <td data-value="-1145664000000" role="cell" class="epp-ar">1933-09-12</td>
      <td role="cell">Aureliaton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Branson</td>
      <td role="cell">Shields</td>
      <td data-value="1252972800000" role="cell" class="epp-ar">2009-09-15</td>
      <td role="cell">New Manuela</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Camryn</td>
      <td role="cell">Von</td>
      <td data-value="485395200000" role="cell" class="epp-ar">1985-05-20</td>
      <td role="cell">North Auroreshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Mya</td>
      <td role="cell">Buckridge</td>
      <td data-value="-1652140800000" role="cell" class="epp-ar">1917-08-25</td>
      <td role="cell">Zoraborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Keira</td>
      <td role="cell">Torp</td>
      <td data-value="1731974400000" role="cell" class="epp-ar">2024-11-19</td>
      <td role="cell">Medhurstshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Edythe</td>
      <td role="cell">Ferry</td>
      <td data-value="-2037657600000" role="cell" class="epp-ar">1905-06-07</td>
      <td role="cell">East Micaela</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Zetta</td>
      <td role="cell">Gleichner</td>
      <td data-value="1311724800000" role="cell" class="epp-ar">2011-07-27</td>
      <td role="cell">Lake Lou</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Barton</td>
      <td role="cell">Fisher</td>
      <td data-value="-316828800000" role="cell" class="epp-ar">1959-12-18</td>
      <td role="cell">South Connieview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Reta</td>
      <td role="cell">Lemke</td>
      <td data-value="1181520000000" role="cell" class="epp-ar">2007-06-11</td>
      <td role="cell">West Juvenal</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Burdette</td>
      <td role="cell">Bayer</td>
      <td data-value="-2052950400000" role="cell" class="epp-ar">1904-12-12</td>
      <td role="cell">Lake Eleanoraburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Kameron</td>
      <td role="cell">Marks</td>
      <td data-value="-1485648000000" role="cell" class="epp-ar">1922-12-04</td>
      <td role="cell">North Ahmadtown</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;
}