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
Northern Ireland Jared Schowalter 1963-06-20 West Orie
Wales Isabel Sipes 2008-10-02 Herzogshire
England Floy Klein 1983-09-07 South Huldachester
England Alyce Walker 1949-08-26 Normafort
Northern Ireland Franz Kiehn 1976-02-22 Port Layne
England Jakayla Ferry 1929-08-11 Eddieview
Wales Kendra Miller 2022-04-10 North Sabrinaland
Scotland Marilou Weber 1976-09-22 North Merritthaven
Northern Ireland Arden Corwin 1962-12-24 Gradyfurt
Wales Camila Roob 1956-05-28 Lake Ida
England Kattie Rutherford 1936-07-05 North Lisa
Northern Ireland Oma Kilback 1982-10-27 Boylefort
England Isaiah Block 1963-04-24 North Shemar
Wales Janet Corkery 1937-03-26 East Dangelofort
Scotland Kailyn Heaney 1996-01-08 East Macy
Northern Ireland Vicenta Ferry 2010-02-16 Lake Maceyside
England Christophe Hauck 2012-02-07 Lake Benton
Scotland Quinn Berge 1924-10-17 Lake Kenton
England Nathen Bahringer 1963-05-16 Princessside
Wales Gerry Purdy 1993-04-08 New Rocioport
Wales Zora Goldner 1993-04-21 West Olentown
England Chauncey Kreiger 1992-08-20 New Kamryn
Scotland Lempi Hirthe 1963-02-06 Elsieside
Northern Ireland Maryse Maggio 2013-04-14 Goodwinstad
Wales Axel Bogisich 1983-02-14 South Jaylinport
Scotland Elouise Vandervort 1999-12-06 New Nico
England Gavin Bogan 1910-05-09 Lake Kennyshire
Northern Ireland Althea Hirthe 1996-08-09 Olsonbury
Wales Adolfo Hyatt 1979-02-10 Kuhnshire
England Malika Hackett 1996-08-19 Port Laylaberg
England Gideon Auer 1927-03-03 South Courtney
Northern Ireland Dudley Feil 1939-04-26 New Dahliafurt
England Kayley Kerluke 1972-11-28 Morarfurt
Northern Ireland Alize Goldner 2016-07-03 Othaton
Wales Toby Purdy 1911-05-23 Maudebury
England Mina Gusikowski 1966-02-21 Turcotteville
Wales Isabell Mann 2010-12-05 Aricland
Northern Ireland Merle McClure 1974-09-11 Lake Cristal
Wales Unique Fay 1934-12-06 West Rodrick
Northern Ireland Lempi Johnson 1963-03-10 Josiannemouth
Northern Ireland Alexandrea Pfeffer 1909-12-06 Durganborough
Scotland Jettie Feest 1994-03-30 Port Paigefurt
Wales Esmeralda Torphy 1929-12-11 Lake Kiera
Northern Ireland Will Flatley 1962-11-30 Newtonstad
Wales Oswaldo Terry 1917-12-03 East Mazie
Scotland Julie Carter 1951-03-02 Walshshire
Wales Nyasia Parker 1985-06-07 Streichshire
England Haley Greenholt 2000-01-01 Mannberg
Wales Linda Gislason 1976-03-15 East Dorthychester
England Otto Koelpin 1928-02-23 North Rory

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">Northern Ireland</td>
      <td role="cell">Jared</td>
      <td role="cell">Schowalter</td>
      <td data-value="-206236800000" role="cell" class="epp-ar">1963-06-20</td>
      <td role="cell">West Orie</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Isabel</td>
      <td role="cell">Sipes</td>
      <td data-value="1222905600000" role="cell" class="epp-ar">2008-10-02</td>
      <td role="cell">Herzogshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Floy</td>
      <td role="cell">Klein</td>
      <td data-value="431740800000" role="cell" class="epp-ar">1983-09-07</td>
      <td role="cell">South Huldachester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Alyce</td>
      <td role="cell">Walker</td>
      <td data-value="-642211200000" role="cell" class="epp-ar">1949-08-26</td>
      <td role="cell">Normafort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Franz</td>
      <td role="cell">Kiehn</td>
      <td data-value="193795200000" role="cell" class="epp-ar">1976-02-22</td>
      <td role="cell">Port Layne</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Jakayla</td>
      <td role="cell">Ferry</td>
      <td data-value="-1274659200000" role="cell" class="epp-ar">1929-08-11</td>
      <td role="cell">Eddieview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Kendra</td>
      <td role="cell">Miller</td>
      <td data-value="1649548800000" role="cell" class="epp-ar">2022-04-10</td>
      <td role="cell">North Sabrinaland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Marilou</td>
      <td role="cell">Weber</td>
      <td data-value="212198400000" role="cell" class="epp-ar">1976-09-22</td>
      <td role="cell">North Merritthaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Arden</td>
      <td role="cell">Corwin</td>
      <td data-value="-221616000000" role="cell" class="epp-ar">1962-12-24</td>
      <td role="cell">Gradyfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Camila</td>
      <td role="cell">Roob</td>
      <td data-value="-429062400000" role="cell" class="epp-ar">1956-05-28</td>
      <td role="cell">Lake Ida</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Kattie</td>
      <td role="cell">Rutherford</td>
      <td data-value="-1056931200000" role="cell" class="epp-ar">1936-07-05</td>
      <td role="cell">North Lisa</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Oma</td>
      <td role="cell">Kilback</td>
      <td data-value="404524800000" role="cell" class="epp-ar">1982-10-27</td>
      <td role="cell">Boylefort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Isaiah</td>
      <td role="cell">Block</td>
      <td data-value="-211161600000" role="cell" class="epp-ar">1963-04-24</td>
      <td role="cell">North Shemar</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Janet</td>
      <td role="cell">Corkery</td>
      <td data-value="-1034121600000" role="cell" class="epp-ar">1937-03-26</td>
      <td role="cell">East Dangelofort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Kailyn</td>
      <td role="cell">Heaney</td>
      <td data-value="821059200000" role="cell" class="epp-ar">1996-01-08</td>
      <td role="cell">East Macy</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Vicenta</td>
      <td role="cell">Ferry</td>
      <td data-value="1266278400000" role="cell" class="epp-ar">2010-02-16</td>
      <td role="cell">Lake Maceyside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Christophe</td>
      <td role="cell">Hauck</td>
      <td data-value="1328572800000" role="cell" class="epp-ar">2012-02-07</td>
      <td role="cell">Lake Benton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Quinn</td>
      <td role="cell">Berge</td>
      <td data-value="-1426636800000" role="cell" class="epp-ar">1924-10-17</td>
      <td role="cell">Lake Kenton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Nathen</td>
      <td role="cell">Bahringer</td>
      <td data-value="-209260800000" role="cell" class="epp-ar">1963-05-16</td>
      <td role="cell">Princessside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Gerry</td>
      <td role="cell">Purdy</td>
      <td data-value="734227200000" role="cell" class="epp-ar">1993-04-08</td>
      <td role="cell">New Rocioport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Zora</td>
      <td role="cell">Goldner</td>
      <td data-value="735350400000" role="cell" class="epp-ar">1993-04-21</td>
      <td role="cell">West Olentown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Chauncey</td>
      <td role="cell">Kreiger</td>
      <td data-value="714268800000" role="cell" class="epp-ar">1992-08-20</td>
      <td role="cell">New Kamryn</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Lempi</td>
      <td role="cell">Hirthe</td>
      <td data-value="-217814400000" role="cell" class="epp-ar">1963-02-06</td>
      <td role="cell">Elsieside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Maryse</td>
      <td role="cell">Maggio</td>
      <td data-value="1365897600000" role="cell" class="epp-ar">2013-04-14</td>
      <td role="cell">Goodwinstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Axel</td>
      <td role="cell">Bogisich</td>
      <td data-value="414028800000" role="cell" class="epp-ar">1983-02-14</td>
      <td role="cell">South Jaylinport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Elouise</td>
      <td role="cell">Vandervort</td>
      <td data-value="944438400000" role="cell" class="epp-ar">1999-12-06</td>
      <td role="cell">New Nico</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Gavin</td>
      <td role="cell">Bogan</td>
      <td data-value="-1882396800000" role="cell" class="epp-ar">1910-05-09</td>
      <td role="cell">Lake Kennyshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Althea</td>
      <td role="cell">Hirthe</td>
      <td data-value="839548800000" role="cell" class="epp-ar">1996-08-09</td>
      <td role="cell">Olsonbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Adolfo</td>
      <td role="cell">Hyatt</td>
      <td data-value="287452800000" role="cell" class="epp-ar">1979-02-10</td>
      <td role="cell">Kuhnshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Malika</td>
      <td role="cell">Hackett</td>
      <td data-value="840412800000" role="cell" class="epp-ar">1996-08-19</td>
      <td role="cell">Port Laylaberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Gideon</td>
      <td role="cell">Auer</td>
      <td data-value="-1351728000000" role="cell" class="epp-ar">1927-03-03</td>
      <td role="cell">South Courtney</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Dudley</td>
      <td role="cell">Feil</td>
      <td data-value="-968371200000" role="cell" class="epp-ar">1939-04-26</td>
      <td role="cell">New Dahliafurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Kayley</td>
      <td role="cell">Kerluke</td>
      <td data-value="91756800000" role="cell" class="epp-ar">1972-11-28</td>
      <td role="cell">Morarfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Alize</td>
      <td role="cell">Goldner</td>
      <td data-value="1467504000000" role="cell" class="epp-ar">2016-07-03</td>
      <td role="cell">Othaton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Toby</td>
      <td role="cell">Purdy</td>
      <td data-value="-1849651200000" role="cell" class="epp-ar">1911-05-23</td>
      <td role="cell">Maudebury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Mina</td>
      <td role="cell">Gusikowski</td>
      <td data-value="-121824000000" role="cell" class="epp-ar">1966-02-21</td>
      <td role="cell">Turcotteville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Isabell</td>
      <td role="cell">Mann</td>
      <td data-value="1291507200000" role="cell" class="epp-ar">2010-12-05</td>
      <td role="cell">Aricland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Merle</td>
      <td role="cell">McClure</td>
      <td data-value="148089600000" role="cell" class="epp-ar">1974-09-11</td>
      <td role="cell">Lake Cristal</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Unique</td>
      <td role="cell">Fay</td>
      <td data-value="-1106784000000" role="cell" class="epp-ar">1934-12-06</td>
      <td role="cell">West Rodrick</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Lempi</td>
      <td role="cell">Johnson</td>
      <td data-value="-215049600000" role="cell" class="epp-ar">1963-03-10</td>
      <td role="cell">Josiannemouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Alexandrea</td>
      <td role="cell">Pfeffer</td>
      <td data-value="-1895702400000" role="cell" class="epp-ar">1909-12-06</td>
      <td role="cell">Durganborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jettie</td>
      <td role="cell">Feest</td>
      <td data-value="764985600000" role="cell" class="epp-ar">1994-03-30</td>
      <td role="cell">Port Paigefurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Esmeralda</td>
      <td role="cell">Torphy</td>
      <td data-value="-1264118400000" role="cell" class="epp-ar">1929-12-11</td>
      <td role="cell">Lake Kiera</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Will</td>
      <td role="cell">Flatley</td>
      <td data-value="-223689600000" role="cell" class="epp-ar">1962-11-30</td>
      <td role="cell">Newtonstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Oswaldo</td>
      <td role="cell">Terry</td>
      <td data-value="-1643500800000" role="cell" class="epp-ar">1917-12-03</td>
      <td role="cell">East Mazie</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Julie</td>
      <td role="cell">Carter</td>
      <td data-value="-594432000000" role="cell" class="epp-ar">1951-03-02</td>
      <td role="cell">Walshshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Nyasia</td>
      <td role="cell">Parker</td>
      <td data-value="486950400000" role="cell" class="epp-ar">1985-06-07</td>
      <td role="cell">Streichshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Haley</td>
      <td role="cell">Greenholt</td>
      <td data-value="946684800000" role="cell" class="epp-ar">2000-01-01</td>
      <td role="cell">Mannberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Linda</td>
      <td role="cell">Gislason</td>
      <td data-value="195696000000" role="cell" class="epp-ar">1976-03-15</td>
      <td role="cell">East Dorthychester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Otto</td>
      <td role="cell">Koelpin</td>
      <td data-value="-1320883200000" role="cell" class="epp-ar">1928-02-23</td>
      <td role="cell">North Rory</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;
}