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 Zita Gutkowski 1964-12-23 Lomaburgh
Scotland Jacinto Krajcik 1992-03-23 Magdalenville
England Afton Bahringer 1955-01-22 New Magalimouth
Northern Ireland Raoul Schmidt 1905-06-04 Quigleyville
England Vada Graham 2000-05-30 South Randitown
Wales Herminia Kassulke 1983-10-25 Trompborough
Northern Ireland Jan Luettgen 1965-03-07 Millshaven
England Orin Hammes 1964-08-07 East Dorianshire
Scotland David Little 1964-10-27 O'Connermouth
Wales Amya Mante 1959-11-27 Lake Sydneefurt
Scotland Ashtyn Parisian 1969-08-21 South Madisenberg
Scotland Nicholas Harvey 1975-05-27 Funkborough
Northern Ireland Anjali Moore 1958-05-17 Schusterport
Wales Elna Crona 2026-05-14 New Janis
Northern Ireland Devonte Murazik 1964-08-16 South Rheastad
England Cordia Hartmann 1973-08-24 Port Anais
England Lamont Lemke 1983-08-11 Sporerton
Northern Ireland Jennifer McClure 1928-08-20 Damarisburgh
Wales Jaycee Stehr 1966-01-21 Hermistonstad
Scotland Palma King 1964-07-21 Elissaberg
Wales Bartholome Carroll 1995-01-05 Majorside
Northern Ireland Frederique Jerde 1947-07-19 Lake Coltonborough
Northern Ireland Vada Thompson 2014-11-30 D'Amorebury
Wales Marty Denesik 1937-03-05 Sipestown
England Adelbert Terry 2016-03-25 East Hadley
Wales Delpha Morar 1934-09-11 Magnustown
Scotland Macie Welch 1969-10-24 Ondrickabury
Wales Marianne Pouros 1969-08-07 New Bennie
Northern Ireland Mia Skiles 1977-12-11 Murphyville
Scotland Lillian Vandervort 1921-02-23 Lake Burnice
England Sim Kris 1987-03-07 Dibbertport
Northern Ireland Nicolas McCullough 1965-04-05 North Chanelleland
Scotland Paul Block 1929-06-25 Prestonmouth
Wales Hayley Ruecker 1969-05-17 Marksmouth
Wales Pamela Miller 1952-10-02 Rashadmouth
Wales Katherine Wisozk 1978-11-08 East Keelystad
Scotland Fabiola Marks 1963-05-01 Bergebury
Wales Mandy Howe 1909-07-13 Stehrchester
England Ludwig Vandervort 1948-04-02 North Daija
Northern Ireland Marilou Blick 1912-05-24 Loniehaven
Scotland Zechariah Gibson 1946-01-18 New Lazaro
Scotland Malika Heller 1964-09-30 Lake Coy
Northern Ireland Lorena Weissnat 1983-11-26 Port Shany
Scotland Aurore Zieme 2010-10-12 North Valentin
Scotland April Halvorson 1945-11-02 Hammeschester
Scotland Cesar Dietrich 1919-03-16 Toniburgh
Northern Ireland Bernhard Glover 2012-10-26 Domenicahaven
Wales Shawna Quitzon 1964-08-31 North Florenciobury
Wales Felipa Sawayn 2017-09-29 Lake Kristophermouth
Scotland Vicente Morar 1990-10-14 East Jeff

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">Zita</td>
      <td role="cell">Gutkowski</td>
      <td data-value="-158544000000" role="cell" class="epp-ar">1964-12-23</td>
      <td role="cell">Lomaburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jacinto</td>
      <td role="cell">Krajcik</td>
      <td data-value="701308800000" role="cell" class="epp-ar">1992-03-23</td>
      <td role="cell">Magdalenville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Afton</td>
      <td role="cell">Bahringer</td>
      <td data-value="-471571200000" role="cell" class="epp-ar">1955-01-22</td>
      <td role="cell">New Magalimouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Raoul</td>
      <td role="cell">Schmidt</td>
      <td data-value="-2037916800000" role="cell" class="epp-ar">1905-06-04</td>
      <td role="cell">Quigleyville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Vada</td>
      <td role="cell">Graham</td>
      <td data-value="959644800000" role="cell" class="epp-ar">2000-05-30</td>
      <td role="cell">South Randitown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Herminia</td>
      <td role="cell">Kassulke</td>
      <td data-value="435888000000" role="cell" class="epp-ar">1983-10-25</td>
      <td role="cell">Trompborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jan</td>
      <td role="cell">Luettgen</td>
      <td data-value="-152150400000" role="cell" class="epp-ar">1965-03-07</td>
      <td role="cell">Millshaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Orin</td>
      <td role="cell">Hammes</td>
      <td data-value="-170467200000" role="cell" class="epp-ar">1964-08-07</td>
      <td role="cell">East Dorianshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">David</td>
      <td role="cell">Little</td>
      <td data-value="-163468800000" role="cell" class="epp-ar">1964-10-27</td>
      <td role="cell">O'Connermouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Amya</td>
      <td role="cell">Mante</td>
      <td data-value="-318643200000" role="cell" class="epp-ar">1959-11-27</td>
      <td role="cell">Lake Sydneefurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Ashtyn</td>
      <td role="cell">Parisian</td>
      <td data-value="-11491200000" role="cell" class="epp-ar">1969-08-21</td>
      <td role="cell">South Madisenberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Nicholas</td>
      <td role="cell">Harvey</td>
      <td data-value="170380800000" role="cell" class="epp-ar">1975-05-27</td>
      <td role="cell">Funkborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Anjali</td>
      <td role="cell">Moore</td>
      <td data-value="-366940800000" role="cell" class="epp-ar">1958-05-17</td>
      <td role="cell">Schusterport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Elna</td>
      <td role="cell">Crona</td>
      <td data-value="1778716800000" role="cell" class="epp-ar">2026-05-14</td>
      <td role="cell">New Janis</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Devonte</td>
      <td role="cell">Murazik</td>
      <td data-value="-169689600000" role="cell" class="epp-ar">1964-08-16</td>
      <td role="cell">South Rheastad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Cordia</td>
      <td role="cell">Hartmann</td>
      <td data-value="114998400000" role="cell" class="epp-ar">1973-08-24</td>
      <td role="cell">Port Anais</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Lamont</td>
      <td role="cell">Lemke</td>
      <td data-value="429408000000" role="cell" class="epp-ar">1983-08-11</td>
      <td role="cell">Sporerton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jennifer</td>
      <td role="cell">McClure</td>
      <td data-value="-1305417600000" role="cell" class="epp-ar">1928-08-20</td>
      <td role="cell">Damarisburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Jaycee</td>
      <td role="cell">Stehr</td>
      <td data-value="-124502400000" role="cell" class="epp-ar">1966-01-21</td>
      <td role="cell">Hermistonstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Palma</td>
      <td role="cell">King</td>
      <td data-value="-171936000000" role="cell" class="epp-ar">1964-07-21</td>
      <td role="cell">Elissaberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Bartholome</td>
      <td role="cell">Carroll</td>
      <td data-value="789264000000" role="cell" class="epp-ar">1995-01-05</td>
      <td role="cell">Majorside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Frederique</td>
      <td role="cell">Jerde</td>
      <td data-value="-708652800000" role="cell" class="epp-ar">1947-07-19</td>
      <td role="cell">Lake Coltonborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Vada</td>
      <td role="cell">Thompson</td>
      <td data-value="1417305600000" role="cell" class="epp-ar">2014-11-30</td>
      <td role="cell">D'Amorebury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Marty</td>
      <td role="cell">Denesik</td>
      <td data-value="-1035936000000" role="cell" class="epp-ar">1937-03-05</td>
      <td role="cell">Sipestown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Adelbert</td>
      <td role="cell">Terry</td>
      <td data-value="1458864000000" role="cell" class="epp-ar">2016-03-25</td>
      <td role="cell">East Hadley</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Delpha</td>
      <td role="cell">Morar</td>
      <td data-value="-1114214400000" role="cell" class="epp-ar">1934-09-11</td>
      <td role="cell">Magnustown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Macie</td>
      <td role="cell">Welch</td>
      <td data-value="-5961600000" role="cell" class="epp-ar">1969-10-24</td>
      <td role="cell">Ondrickabury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Marianne</td>
      <td role="cell">Pouros</td>
      <td data-value="-12700800000" role="cell" class="epp-ar">1969-08-07</td>
      <td role="cell">New Bennie</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Mia</td>
      <td role="cell">Skiles</td>
      <td data-value="250646400000" role="cell" class="epp-ar">1977-12-11</td>
      <td role="cell">Murphyville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Lillian</td>
      <td role="cell">Vandervort</td>
      <td data-value="-1541721600000" role="cell" class="epp-ar">1921-02-23</td>
      <td role="cell">Lake Burnice</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Sim</td>
      <td role="cell">Kris</td>
      <td data-value="542073600000" role="cell" class="epp-ar">1987-03-07</td>
      <td role="cell">Dibbertport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Nicolas</td>
      <td role="cell">McCullough</td>
      <td data-value="-149644800000" role="cell" class="epp-ar">1965-04-05</td>
      <td role="cell">North Chanelleland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Paul</td>
      <td role="cell">Block</td>
      <td data-value="-1278720000000" role="cell" class="epp-ar">1929-06-25</td>
      <td role="cell">Prestonmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Hayley</td>
      <td role="cell">Ruecker</td>
      <td data-value="-19785600000" role="cell" class="epp-ar">1969-05-17</td>
      <td role="cell">Marksmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Pamela</td>
      <td role="cell">Miller</td>
      <td data-value="-544320000000" role="cell" class="epp-ar">1952-10-02</td>
      <td role="cell">Rashadmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Katherine</td>
      <td role="cell">Wisozk</td>
      <td data-value="279331200000" role="cell" class="epp-ar">1978-11-08</td>
      <td role="cell">East Keelystad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Fabiola</td>
      <td role="cell">Marks</td>
      <td data-value="-210556800000" role="cell" class="epp-ar">1963-05-01</td>
      <td role="cell">Bergebury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Mandy</td>
      <td role="cell">Howe</td>
      <td data-value="-1908316800000" role="cell" class="epp-ar">1909-07-13</td>
      <td role="cell">Stehrchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Ludwig</td>
      <td role="cell">Vandervort</td>
      <td data-value="-686361600000" role="cell" class="epp-ar">1948-04-02</td>
      <td role="cell">North Daija</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Marilou</td>
      <td role="cell">Blick</td>
      <td data-value="-1817942400000" role="cell" class="epp-ar">1912-05-24</td>
      <td role="cell">Loniehaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Zechariah</td>
      <td role="cell">Gibson</td>
      <td data-value="-755913600000" role="cell" class="epp-ar">1946-01-18</td>
      <td role="cell">New Lazaro</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Malika</td>
      <td role="cell">Heller</td>
      <td data-value="-165801600000" role="cell" class="epp-ar">1964-09-30</td>
      <td role="cell">Lake Coy</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Lorena</td>
      <td role="cell">Weissnat</td>
      <td data-value="438652800000" role="cell" class="epp-ar">1983-11-26</td>
      <td role="cell">Port Shany</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Aurore</td>
      <td role="cell">Zieme</td>
      <td data-value="1286841600000" role="cell" class="epp-ar">2010-10-12</td>
      <td role="cell">North Valentin</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">April</td>
      <td role="cell">Halvorson</td>
      <td data-value="-762566400000" role="cell" class="epp-ar">1945-11-02</td>
      <td role="cell">Hammeschester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Cesar</td>
      <td role="cell">Dietrich</td>
      <td data-value="-1603065600000" role="cell" class="epp-ar">1919-03-16</td>
      <td role="cell">Toniburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Bernhard</td>
      <td role="cell">Glover</td>
      <td data-value="1351209600000" role="cell" class="epp-ar">2012-10-26</td>
      <td role="cell">Domenicahaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Shawna</td>
      <td role="cell">Quitzon</td>
      <td data-value="-168393600000" role="cell" class="epp-ar">1964-08-31</td>
      <td role="cell">North Florenciobury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Felipa</td>
      <td role="cell">Sawayn</td>
      <td data-value="1506643200000" role="cell" class="epp-ar">2017-09-29</td>
      <td role="cell">Lake Kristophermouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Vicente</td>
      <td role="cell">Morar</td>
      <td data-value="655862400000" role="cell" class="epp-ar">1990-10-14</td>
      <td role="cell">East Jeff</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;
}