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 Melyna Hilll 1960-03-03 East Joanfort
Wales Curt Robel 1920-09-04 Earlineland
Wales Colby Watsica 1968-12-05 New Evertborough
Wales Jameson Wilderman 1950-01-12 Haagshire
Wales Alberto Kertzmann 1937-06-27 Pearlieport
Wales Giovani Lynch 1984-04-20 Predovicview
Scotland Vicente Kuvalis 1964-09-18 West Chaya
Northern Ireland Bernadine Kunze 1987-05-30 Makenzieport
England Justice Rau 1942-01-20 Yvetteville
England Alivia Klocko 1956-09-01 Effertzmouth
England Mayra Ward 1989-09-26 Alexanderchester
Wales Charles Schimmel 1987-05-24 O'Reillymouth
England Leland Treutel 2010-07-03 Lake Merrittbury
Northern Ireland Alta Mohr 1991-10-23 Beertown
Scotland Aric Anderson 1950-03-05 Lake Talia
Scotland Janessa Ortiz 1964-09-15 Port Catherine
Wales Raymundo Sipes 1958-04-24 O'Connerville
Wales Madeline Schamberger 1905-04-19 North Trey
Scotland Katarina McKenzie 1994-08-05 Schmelerbury
Wales Florence Goldner 1927-10-04 North Catalina
Wales Brook Ruecker 1964-09-20 Bergebury
Scotland Jensen Bechtelar 1951-02-09 Rosalindberg
England Devon Sauer 1984-08-24 Port Annabelle
Wales Cara Stokes 1978-03-09 Annetteland
Scotland April Wolf 1963-11-06 Rutherfordview
Scotland Alayna Stamm 1994-01-21 East Casimer
Scotland Leopold Stracke 1973-10-13 East Kadeside
Northern Ireland Destinee Berge 1925-03-29 New Melba
Northern Ireland Queen Denesik 1973-05-02 Estrellastad
Wales Erling Ledner 1951-04-09 Jaydeport
Scotland Lee Mayert 1986-05-03 Boyleborough
England Lawrence Smitham 1934-09-12 Port Wilma
Northern Ireland Jamaal Howell 1945-07-13 Lake Oma
Wales Tara Kuphal 1936-01-26 New Lunaville
Wales Jena Kozey 1964-02-24 Jaylentown
Wales Luella Krajcik 1951-05-03 New Morris
Northern Ireland Margarett Corkery 2020-08-05 Johnpaulland
Northern Ireland Isac Bashirian 1921-02-08 Jonesside
Scotland Althea Gleichner 2015-08-11 Devanmouth
Northern Ireland Nathan Bartoletti 1964-05-07 Destintown
England Jamarcus Swift 1955-07-13 Dorothyburgh
Northern Ireland Estefania Kuhlman 1964-08-18 Isomland
Northern Ireland William Prohaska 1964-11-30 North Issacborough
England Gaylord Bartoletti 1979-04-27 South Esperanzaside
Scotland Kip Brown 1910-01-08 Armstrongmouth
Northern Ireland Sasha Cartwright 2016-08-18 Domenicview
Wales Christopher Bradtke 2025-01-06 South Hughland
Northern Ireland Maurine Labadie 1920-01-31 Chayatown
Northern Ireland Clifford Reichel 1962-07-05 East Rowland
Scotland Jess Bosco 1979-02-19 Marquardtside

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">Melyna</td>
      <td role="cell">Hilll</td>
      <td data-value="-310262400000" role="cell" class="epp-ar">1960-03-03</td>
      <td role="cell">East Joanfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Curt</td>
      <td role="cell">Robel</td>
      <td data-value="-1556582400000" role="cell" class="epp-ar">1920-09-04</td>
      <td role="cell">Earlineland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Colby</td>
      <td role="cell">Watsica</td>
      <td data-value="-33868800000" role="cell" class="epp-ar">1968-12-05</td>
      <td role="cell">New Evertborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Jameson</td>
      <td role="cell">Wilderman</td>
      <td data-value="-630201600000" role="cell" class="epp-ar">1950-01-12</td>
      <td role="cell">Haagshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Alberto</td>
      <td role="cell">Kertzmann</td>
      <td data-value="-1026086400000" role="cell" class="epp-ar">1937-06-27</td>
      <td role="cell">Pearlieport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Giovani</td>
      <td role="cell">Lynch</td>
      <td data-value="451267200000" role="cell" class="epp-ar">1984-04-20</td>
      <td role="cell">Predovicview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Vicente</td>
      <td role="cell">Kuvalis</td>
      <td data-value="-166838400000" role="cell" class="epp-ar">1964-09-18</td>
      <td role="cell">West Chaya</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Bernadine</td>
      <td role="cell">Kunze</td>
      <td data-value="549331200000" role="cell" class="epp-ar">1987-05-30</td>
      <td role="cell">Makenzieport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Justice</td>
      <td role="cell">Rau</td>
      <td data-value="-881971200000" role="cell" class="epp-ar">1942-01-20</td>
      <td role="cell">Yvetteville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Alivia</td>
      <td role="cell">Klocko</td>
      <td data-value="-420768000000" role="cell" class="epp-ar">1956-09-01</td>
      <td role="cell">Effertzmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Mayra</td>
      <td role="cell">Ward</td>
      <td data-value="622771200000" role="cell" class="epp-ar">1989-09-26</td>
      <td role="cell">Alexanderchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Charles</td>
      <td role="cell">Schimmel</td>
      <td data-value="548812800000" role="cell" class="epp-ar">1987-05-24</td>
      <td role="cell">O'Reillymouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Leland</td>
      <td role="cell">Treutel</td>
      <td data-value="1278115200000" role="cell" class="epp-ar">2010-07-03</td>
      <td role="cell">Lake Merrittbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Alta</td>
      <td role="cell">Mohr</td>
      <td data-value="688176000000" role="cell" class="epp-ar">1991-10-23</td>
      <td role="cell">Beertown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Aric</td>
      <td role="cell">Anderson</td>
      <td data-value="-625708800000" role="cell" class="epp-ar">1950-03-05</td>
      <td role="cell">Lake Talia</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Janessa</td>
      <td role="cell">Ortiz</td>
      <td data-value="-167097600000" role="cell" class="epp-ar">1964-09-15</td>
      <td role="cell">Port Catherine</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Raymundo</td>
      <td role="cell">Sipes</td>
      <td data-value="-368928000000" role="cell" class="epp-ar">1958-04-24</td>
      <td role="cell">O'Connerville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Madeline</td>
      <td role="cell">Schamberger</td>
      <td data-value="-2041891200000" role="cell" class="epp-ar">1905-04-19</td>
      <td role="cell">North Trey</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Katarina</td>
      <td role="cell">McKenzie</td>
      <td data-value="776044800000" role="cell" class="epp-ar">1994-08-05</td>
      <td role="cell">Schmelerbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Florence</td>
      <td role="cell">Goldner</td>
      <td data-value="-1333152000000" role="cell" class="epp-ar">1927-10-04</td>
      <td role="cell">North Catalina</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Brook</td>
      <td role="cell">Ruecker</td>
      <td data-value="-166665600000" role="cell" class="epp-ar">1964-09-20</td>
      <td role="cell">Bergebury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jensen</td>
      <td role="cell">Bechtelar</td>
      <td data-value="-596246400000" role="cell" class="epp-ar">1951-02-09</td>
      <td role="cell">Rosalindberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Devon</td>
      <td role="cell">Sauer</td>
      <td data-value="462153600000" role="cell" class="epp-ar">1984-08-24</td>
      <td role="cell">Port Annabelle</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Cara</td>
      <td role="cell">Stokes</td>
      <td data-value="258249600000" role="cell" class="epp-ar">1978-03-09</td>
      <td role="cell">Annetteland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">April</td>
      <td role="cell">Wolf</td>
      <td data-value="-194227200000" role="cell" class="epp-ar">1963-11-06</td>
      <td role="cell">Rutherfordview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Alayna</td>
      <td role="cell">Stamm</td>
      <td data-value="759110400000" role="cell" class="epp-ar">1994-01-21</td>
      <td role="cell">East Casimer</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Leopold</td>
      <td role="cell">Stracke</td>
      <td data-value="119318400000" role="cell" class="epp-ar">1973-10-13</td>
      <td role="cell">East Kadeside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Destinee</td>
      <td role="cell">Berge</td>
      <td data-value="-1412553600000" role="cell" class="epp-ar">1925-03-29</td>
      <td role="cell">New Melba</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Queen</td>
      <td role="cell">Denesik</td>
      <td data-value="105148800000" role="cell" class="epp-ar">1973-05-02</td>
      <td role="cell">Estrellastad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Erling</td>
      <td role="cell">Ledner</td>
      <td data-value="-591148800000" role="cell" class="epp-ar">1951-04-09</td>
      <td role="cell">Jaydeport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Lee</td>
      <td role="cell">Mayert</td>
      <td data-value="515462400000" role="cell" class="epp-ar">1986-05-03</td>
      <td role="cell">Boyleborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Lawrence</td>
      <td role="cell">Smitham</td>
      <td data-value="-1114128000000" role="cell" class="epp-ar">1934-09-12</td>
      <td role="cell">Port Wilma</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jamaal</td>
      <td role="cell">Howell</td>
      <td data-value="-772243200000" role="cell" class="epp-ar">1945-07-13</td>
      <td role="cell">Lake Oma</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Tara</td>
      <td role="cell">Kuphal</td>
      <td data-value="-1070841600000" role="cell" class="epp-ar">1936-01-26</td>
      <td role="cell">New Lunaville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Jena</td>
      <td role="cell">Kozey</td>
      <td data-value="-184723200000" role="cell" class="epp-ar">1964-02-24</td>
      <td role="cell">Jaylentown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Luella</td>
      <td role="cell">Krajcik</td>
      <td data-value="-589075200000" role="cell" class="epp-ar">1951-05-03</td>
      <td role="cell">New Morris</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Margarett</td>
      <td role="cell">Corkery</td>
      <td data-value="1596585600000" role="cell" class="epp-ar">2020-08-05</td>
      <td role="cell">Johnpaulland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Isac</td>
      <td role="cell">Bashirian</td>
      <td data-value="-1543017600000" role="cell" class="epp-ar">1921-02-08</td>
      <td role="cell">Jonesside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Althea</td>
      <td role="cell">Gleichner</td>
      <td data-value="1439251200000" role="cell" class="epp-ar">2015-08-11</td>
      <td role="cell">Devanmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Nathan</td>
      <td role="cell">Bartoletti</td>
      <td data-value="-178416000000" role="cell" class="epp-ar">1964-05-07</td>
      <td role="cell">Destintown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Jamarcus</td>
      <td role="cell">Swift</td>
      <td data-value="-456710400000" role="cell" class="epp-ar">1955-07-13</td>
      <td role="cell">Dorothyburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Estefania</td>
      <td role="cell">Kuhlman</td>
      <td data-value="-169516800000" role="cell" class="epp-ar">1964-08-18</td>
      <td role="cell">Isomland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">William</td>
      <td role="cell">Prohaska</td>
      <td data-value="-160531200000" role="cell" class="epp-ar">1964-11-30</td>
      <td role="cell">North Issacborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Gaylord</td>
      <td role="cell">Bartoletti</td>
      <td data-value="294019200000" role="cell" class="epp-ar">1979-04-27</td>
      <td role="cell">South Esperanzaside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Kip</td>
      <td role="cell">Brown</td>
      <td data-value="-1892851200000" role="cell" class="epp-ar">1910-01-08</td>
      <td role="cell">Armstrongmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Sasha</td>
      <td role="cell">Cartwright</td>
      <td data-value="1471478400000" role="cell" class="epp-ar">2016-08-18</td>
      <td role="cell">Domenicview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Christopher</td>
      <td role="cell">Bradtke</td>
      <td data-value="1736121600000" role="cell" class="epp-ar">2025-01-06</td>
      <td role="cell">South Hughland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Maurine</td>
      <td role="cell">Labadie</td>
      <td data-value="-1575331200000" role="cell" class="epp-ar">1920-01-31</td>
      <td role="cell">Chayatown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Clifford</td>
      <td role="cell">Reichel</td>
      <td data-value="-236476800000" role="cell" class="epp-ar">1962-07-05</td>
      <td role="cell">East Rowland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jess</td>
      <td role="cell">Bosco</td>
      <td data-value="288230400000" role="cell" class="epp-ar">1979-02-19</td>
      <td role="cell">Marquardtside</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;
}