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 Charles Quitzon 1908-02-11 O'Connellmouth
England Easton Ebert 1956-09-30 East Jerry
Northern Ireland Maximilian Cruickshank 2000-11-23 Jonathanberg
Wales Titus Jacobson 1949-08-18 East Blanche
Wales Rosalyn Kuhic 2009-10-12 New Hailee
Wales Maya Baumbach 1950-03-29 New Kameronchester
Northern Ireland Emely Leffler 1968-04-04 Lake Lolaberg
Scotland Marilyne Ziemann 1988-12-06 Ebertmouth
Wales Stephon Wiegand 1999-07-04 Tyshawnton
Wales Kelvin Nolan 1929-05-30 Eliton
England Oscar Cartwright 2007-12-22 Lake Newtonbury
Northern Ireland Idella Bode 1963-09-29 Kossbury
Wales Yessenia Mohr 1969-12-15 Ratkeville
England Gay Beier 1930-03-15 Daughertyside
Northern Ireland Francesca Boyer 2020-10-03 New Oceane
Wales Mallory Hackett 1977-10-07 Dayneshire
England Sibyl Mayer 1980-11-05 East Evertbury
Wales Orville Lubowitz 1926-01-29 Mohrshire
Wales Oleta Aufderhar 1979-03-16 Gailmouth
Scotland Mona Kertzmann 1998-02-07 New Adrainmouth
Northern Ireland Davion Parisian 1941-04-13 Madisonville
Scotland Eliane Harber 1968-04-10 South Lelatown
England Randy Glover 1963-09-10 South Domenico
Northern Ireland Lina Lang 1994-10-05 Hellerville
Wales Destany Ward 1943-06-04 New Lancebury
Scotland Cooper Windler 2013-08-06 Lake Kelton
England Reese Langworth 1962-04-11 Lake Tannershire
Northern Ireland Zelma Spinka 1998-10-08 Howellport
Northern Ireland Hollis Prosacco 1948-03-23 West Michele
Northern Ireland Sandrine Windler 1963-08-25 East Morganview
Scotland Paula Funk 1905-07-16 Murrayport
Northern Ireland Rossie Schmidt 1981-03-20 Wolfborough
England Yolanda O'Kon 2025-04-19 Pacochachester
Scotland Ricky O'Conner 1927-04-07 Port Araburgh
Scotland Vivianne Casper 1963-02-25 North Friedrich
Scotland Dina Lebsack 1943-01-13 O'Connerside
England Alf Lebsack 1979-08-03 North Evafort
Northern Ireland Gay Hayes 2012-07-30 Lake Ronny
Scotland Erna Kirlin 1935-03-07 Ornmouth
Wales Consuelo Lowe 1919-03-06 Lake Myafurt
England Thomas Wolf 1938-10-13 Louveniaburgh
Wales Reyes Blick 2003-08-04 West Darryl
Scotland Erik Rempel 1942-11-03 Morarstad
Wales Lew Adams 2014-10-06 New Sylviahaven
Northern Ireland Sage Abernathy 1932-07-13 Port Nikkiton
Scotland Tanner Ebert 2022-11-23 Schultzland
Scotland Cody Towne 1967-04-09 Mathiasstad
Wales Rosalind Rau 2005-03-19 New Theo
Northern Ireland Isadore Bode 1929-01-12 Michealland
Wales Aida Rogahn 2016-11-29 Port Brionna

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">Charles</td>
      <td role="cell">Quitzon</td>
      <td data-value="-1953072000000" role="cell" class="epp-ar">1908-02-11</td>
      <td role="cell">O'Connellmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Easton</td>
      <td role="cell">Ebert</td>
      <td data-value="-418262400000" role="cell" class="epp-ar">1956-09-30</td>
      <td role="cell">East Jerry</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Maximilian</td>
      <td role="cell">Cruickshank</td>
      <td data-value="974937600000" role="cell" class="epp-ar">2000-11-23</td>
      <td role="cell">Jonathanberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Titus</td>
      <td role="cell">Jacobson</td>
      <td data-value="-642902400000" role="cell" class="epp-ar">1949-08-18</td>
      <td role="cell">East Blanche</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Rosalyn</td>
      <td role="cell">Kuhic</td>
      <td data-value="1255305600000" role="cell" class="epp-ar">2009-10-12</td>
      <td role="cell">New Hailee</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Maya</td>
      <td role="cell">Baumbach</td>
      <td data-value="-623635200000" role="cell" class="epp-ar">1950-03-29</td>
      <td role="cell">New Kameronchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Emely</td>
      <td role="cell">Leffler</td>
      <td data-value="-55036800000" role="cell" class="epp-ar">1968-04-04</td>
      <td role="cell">Lake Lolaberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Marilyne</td>
      <td role="cell">Ziemann</td>
      <td data-value="597369600000" role="cell" class="epp-ar">1988-12-06</td>
      <td role="cell">Ebertmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Stephon</td>
      <td role="cell">Wiegand</td>
      <td data-value="931046400000" role="cell" class="epp-ar">1999-07-04</td>
      <td role="cell">Tyshawnton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Kelvin</td>
      <td role="cell">Nolan</td>
      <td data-value="-1280966400000" role="cell" class="epp-ar">1929-05-30</td>
      <td role="cell">Eliton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Oscar</td>
      <td role="cell">Cartwright</td>
      <td data-value="1198281600000" role="cell" class="epp-ar">2007-12-22</td>
      <td role="cell">Lake Newtonbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Idella</td>
      <td role="cell">Bode</td>
      <td data-value="-197510400000" role="cell" class="epp-ar">1963-09-29</td>
      <td role="cell">Kossbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Yessenia</td>
      <td role="cell">Mohr</td>
      <td data-value="-1468800000" role="cell" class="epp-ar">1969-12-15</td>
      <td role="cell">Ratkeville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Gay</td>
      <td role="cell">Beier</td>
      <td data-value="-1255996800000" role="cell" class="epp-ar">1930-03-15</td>
      <td role="cell">Daughertyside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Francesca</td>
      <td role="cell">Boyer</td>
      <td data-value="1601683200000" role="cell" class="epp-ar">2020-10-03</td>
      <td role="cell">New Oceane</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Mallory</td>
      <td role="cell">Hackett</td>
      <td data-value="245030400000" role="cell" class="epp-ar">1977-10-07</td>
      <td role="cell">Dayneshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Sibyl</td>
      <td role="cell">Mayer</td>
      <td data-value="342230400000" role="cell" class="epp-ar">1980-11-05</td>
      <td role="cell">East Evertbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Orville</td>
      <td role="cell">Lubowitz</td>
      <td data-value="-1386115200000" role="cell" class="epp-ar">1926-01-29</td>
      <td role="cell">Mohrshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Oleta</td>
      <td role="cell">Aufderhar</td>
      <td data-value="290390400000" role="cell" class="epp-ar">1979-03-16</td>
      <td role="cell">Gailmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Mona</td>
      <td role="cell">Kertzmann</td>
      <td data-value="886809600000" role="cell" class="epp-ar">1998-02-07</td>
      <td role="cell">New Adrainmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Davion</td>
      <td role="cell">Parisian</td>
      <td data-value="-906336000000" role="cell" class="epp-ar">1941-04-13</td>
      <td role="cell">Madisonville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Eliane</td>
      <td role="cell">Harber</td>
      <td data-value="-54518400000" role="cell" class="epp-ar">1968-04-10</td>
      <td role="cell">South Lelatown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Randy</td>
      <td role="cell">Glover</td>
      <td data-value="-199152000000" role="cell" class="epp-ar">1963-09-10</td>
      <td role="cell">South Domenico</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Lina</td>
      <td role="cell">Lang</td>
      <td data-value="781315200000" role="cell" class="epp-ar">1994-10-05</td>
      <td role="cell">Hellerville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Destany</td>
      <td role="cell">Ward</td>
      <td data-value="-838771200000" role="cell" class="epp-ar">1943-06-04</td>
      <td role="cell">New Lancebury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Cooper</td>
      <td role="cell">Windler</td>
      <td data-value="1375747200000" role="cell" class="epp-ar">2013-08-06</td>
      <td role="cell">Lake Kelton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Reese</td>
      <td role="cell">Langworth</td>
      <td data-value="-243820800000" role="cell" class="epp-ar">1962-04-11</td>
      <td role="cell">Lake Tannershire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Zelma</td>
      <td role="cell">Spinka</td>
      <td data-value="907804800000" role="cell" class="epp-ar">1998-10-08</td>
      <td role="cell">Howellport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Hollis</td>
      <td role="cell">Prosacco</td>
      <td data-value="-687225600000" role="cell" class="epp-ar">1948-03-23</td>
      <td role="cell">West Michele</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Sandrine</td>
      <td role="cell">Windler</td>
      <td data-value="-200534400000" role="cell" class="epp-ar">1963-08-25</td>
      <td role="cell">East Morganview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Paula</td>
      <td role="cell">Funk</td>
      <td data-value="-2034288000000" role="cell" class="epp-ar">1905-07-16</td>
      <td role="cell">Murrayport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Rossie</td>
      <td role="cell">Schmidt</td>
      <td data-value="353894400000" role="cell" class="epp-ar">1981-03-20</td>
      <td role="cell">Wolfborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Yolanda</td>
      <td role="cell">O'Kon</td>
      <td data-value="1745020800000" role="cell" class="epp-ar">2025-04-19</td>
      <td role="cell">Pacochachester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Ricky</td>
      <td role="cell">O'Conner</td>
      <td data-value="-1348704000000" role="cell" class="epp-ar">1927-04-07</td>
      <td role="cell">Port Araburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Vivianne</td>
      <td role="cell">Casper</td>
      <td data-value="-216172800000" role="cell" class="epp-ar">1963-02-25</td>
      <td role="cell">North Friedrich</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Dina</td>
      <td role="cell">Lebsack</td>
      <td data-value="-851040000000" role="cell" class="epp-ar">1943-01-13</td>
      <td role="cell">O'Connerside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Alf</td>
      <td role="cell">Lebsack</td>
      <td data-value="302486400000" role="cell" class="epp-ar">1979-08-03</td>
      <td role="cell">North Evafort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Gay</td>
      <td role="cell">Hayes</td>
      <td data-value="1343606400000" role="cell" class="epp-ar">2012-07-30</td>
      <td role="cell">Lake Ronny</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Erna</td>
      <td role="cell">Kirlin</td>
      <td data-value="-1098921600000" role="cell" class="epp-ar">1935-03-07</td>
      <td role="cell">Ornmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Consuelo</td>
      <td role="cell">Lowe</td>
      <td data-value="-1603929600000" role="cell" class="epp-ar">1919-03-06</td>
      <td role="cell">Lake Myafurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Thomas</td>
      <td role="cell">Wolf</td>
      <td data-value="-985219200000" role="cell" class="epp-ar">1938-10-13</td>
      <td role="cell">Louveniaburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Reyes</td>
      <td role="cell">Blick</td>
      <td data-value="1059955200000" role="cell" class="epp-ar">2003-08-04</td>
      <td role="cell">West Darryl</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Erik</td>
      <td role="cell">Rempel</td>
      <td data-value="-857174400000" role="cell" class="epp-ar">1942-11-03</td>
      <td role="cell">Morarstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Lew</td>
      <td role="cell">Adams</td>
      <td data-value="1412553600000" role="cell" class="epp-ar">2014-10-06</td>
      <td role="cell">New Sylviahaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Sage</td>
      <td role="cell">Abernathy</td>
      <td data-value="-1182470400000" role="cell" class="epp-ar">1932-07-13</td>
      <td role="cell">Port Nikkiton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Tanner</td>
      <td role="cell">Ebert</td>
      <td data-value="1669161600000" role="cell" class="epp-ar">2022-11-23</td>
      <td role="cell">Schultzland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Cody</td>
      <td role="cell">Towne</td>
      <td data-value="-86227200000" role="cell" class="epp-ar">1967-04-09</td>
      <td role="cell">Mathiasstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Rosalind</td>
      <td role="cell">Rau</td>
      <td data-value="1111190400000" role="cell" class="epp-ar">2005-03-19</td>
      <td role="cell">New Theo</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Isadore</td>
      <td role="cell">Bode</td>
      <td data-value="-1292889600000" role="cell" class="epp-ar">1929-01-12</td>
      <td role="cell">Michealland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Aida</td>
      <td role="cell">Rogahn</td>
      <td data-value="1480377600000" role="cell" class="epp-ar">2016-11-29</td>
      <td role="cell">Port Brionna</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;
}