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 Kendra Schimmel 1975-08-31 Port Aldenberg
Northern Ireland Emil Quigley 1922-07-16 North Theodoraside
Northern Ireland Ruby Bahringer 2006-12-23 Dominiqueview
Northern Ireland Darryl Hauck 1963-09-28 Kesslerland
England Everette Cormier 1986-09-08 Labadiefurt
Scotland Shanie Herzog 2017-01-21 New Ottofort
Northern Ireland Dedric Haag 1987-08-12 Eliseofurt
Wales Luna Ondricka 1982-05-02 Cortneyton
England Charlie Kreiger 1964-03-08 Kaelafurt
Northern Ireland Tracy Ernser 1999-04-11 Robertamouth
Scotland Jacques Roob 2002-10-11 New Krista
Wales Roy Cummings 1956-10-13 Destinyview
Scotland Arvilla Wiza 1981-06-23 Friesenmouth
Scotland Broderick Kovacek 1947-01-30 Marcberg
Wales Holden Waters 1957-06-14 Stantonburgh
Wales Elody Dach 1937-02-24 North Lelah
Wales Libbie Dickens 1954-03-12 Jewesschester
England Emile Johns 1902-12-19 New Kamron
Wales Lawson Quigley 1926-08-14 West Darionhaven
England Daren Moen 1970-02-28 South Kristopher
Scotland Aglae Tromp 1963-09-03 Arelyfort
Northern Ireland Johnnie Huels 1963-07-02 Nasirmouth
England Merle Wiegand 1941-03-24 Bartellchester
Scotland Adam Huel 2003-11-14 Gissellemouth
Northern Ireland Blake Hauck 1922-10-09 South Spencertown
England Haskell Friesen 1962-01-16 South Marionhaven
England Rosetta Braun 1964-01-15 Reingerview
Wales Vaughn Labadie 2000-12-08 VonRuedenville
England Gayle Brown 1988-10-27 North Myrna
Northern Ireland Gillian Yundt 2010-08-31 Boehmland
Northern Ireland Micheal Kreiger 1965-05-08 West Estellaview
Scotland Lauren Wolf 1945-08-11 Port Winfieldberg
England Marlen Schaden 2016-10-27 Port Alvenabury
Wales Verner McLaughlin 1991-04-16 North Myatown
Scotland Lilliana Romaguera 1936-12-19 West Blaze
England Janae Ondricka 1924-09-28 South Rocky
Scotland Leilani Macejkovic 1941-02-01 Lake Burnice
Scotland Janick King 1979-12-15 North Giovaniland
Scotland Ulices Johnson 2022-09-28 Wolffside
England Kitty Medhurst 1912-03-24 Lake Kaylee
Wales Raymundo Mann 1949-01-07 Port Maynard
England Angelica Marquardt 1967-02-07 Evansmouth
England Britney Koepp 1995-01-17 South Loma
Scotland Cecil Hartmann 1919-12-14 Lorafurt
Scotland Sigmund Prohaska 1970-09-05 Lourdesport
Northern Ireland Dino Romaguera 2007-08-19 Leannonshire
Scotland Don Stiedemann 1979-02-13 Americofurt
England Cicero Marquardt 1969-07-05 Johnstonshire
Scotland Elna Bernier 1920-06-09 Lednerstad
Scotland Antonette Flatley 1997-12-25 New Demondhaven

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">Kendra</td>
      <td role="cell">Schimmel</td>
      <td data-value="178675200000" role="cell" class="epp-ar">1975-08-31</td>
      <td role="cell">Port Aldenberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Emil</td>
      <td role="cell">Quigley</td>
      <td data-value="-1497830400000" role="cell" class="epp-ar">1922-07-16</td>
      <td role="cell">North Theodoraside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Ruby</td>
      <td role="cell">Bahringer</td>
      <td data-value="1166832000000" role="cell" class="epp-ar">2006-12-23</td>
      <td role="cell">Dominiqueview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Darryl</td>
      <td role="cell">Hauck</td>
      <td data-value="-197596800000" role="cell" class="epp-ar">1963-09-28</td>
      <td role="cell">Kesslerland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Everette</td>
      <td role="cell">Cormier</td>
      <td data-value="526521600000" role="cell" class="epp-ar">1986-09-08</td>
      <td role="cell">Labadiefurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Shanie</td>
      <td role="cell">Herzog</td>
      <td data-value="1484956800000" role="cell" class="epp-ar">2017-01-21</td>
      <td role="cell">New Ottofort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Dedric</td>
      <td role="cell">Haag</td>
      <td data-value="555724800000" role="cell" class="epp-ar">1987-08-12</td>
      <td role="cell">Eliseofurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Luna</td>
      <td role="cell">Ondricka</td>
      <td data-value="389145600000" role="cell" class="epp-ar">1982-05-02</td>
      <td role="cell">Cortneyton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Charlie</td>
      <td role="cell">Kreiger</td>
      <td data-value="-183600000000" role="cell" class="epp-ar">1964-03-08</td>
      <td role="cell">Kaelafurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Tracy</td>
      <td role="cell">Ernser</td>
      <td data-value="923788800000" role="cell" class="epp-ar">1999-04-11</td>
      <td role="cell">Robertamouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jacques</td>
      <td role="cell">Roob</td>
      <td data-value="1034294400000" role="cell" class="epp-ar">2002-10-11</td>
      <td role="cell">New Krista</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Roy</td>
      <td role="cell">Cummings</td>
      <td data-value="-417139200000" role="cell" class="epp-ar">1956-10-13</td>
      <td role="cell">Destinyview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Arvilla</td>
      <td role="cell">Wiza</td>
      <td data-value="362102400000" role="cell" class="epp-ar">1981-06-23</td>
      <td role="cell">Friesenmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Broderick</td>
      <td role="cell">Kovacek</td>
      <td data-value="-723340800000" role="cell" class="epp-ar">1947-01-30</td>
      <td role="cell">Marcberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Holden</td>
      <td role="cell">Waters</td>
      <td data-value="-396057600000" role="cell" class="epp-ar">1957-06-14</td>
      <td role="cell">Stantonburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Elody</td>
      <td role="cell">Dach</td>
      <td data-value="-1036713600000" role="cell" class="epp-ar">1937-02-24</td>
      <td role="cell">North Lelah</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Libbie</td>
      <td role="cell">Dickens</td>
      <td data-value="-498873600000" role="cell" class="epp-ar">1954-03-12</td>
      <td role="cell">Jewesschester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Emile</td>
      <td role="cell">Johns</td>
      <td data-value="-2115504000000" role="cell" class="epp-ar">1902-12-19</td>
      <td role="cell">New Kamron</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Lawson</td>
      <td role="cell">Quigley</td>
      <td data-value="-1369094400000" role="cell" class="epp-ar">1926-08-14</td>
      <td role="cell">West Darionhaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Daren</td>
      <td role="cell">Moen</td>
      <td data-value="5011200000" role="cell" class="epp-ar">1970-02-28</td>
      <td role="cell">South Kristopher</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Aglae</td>
      <td role="cell">Tromp</td>
      <td data-value="-199756800000" role="cell" class="epp-ar">1963-09-03</td>
      <td role="cell">Arelyfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Johnnie</td>
      <td role="cell">Huels</td>
      <td data-value="-205200000000" role="cell" class="epp-ar">1963-07-02</td>
      <td role="cell">Nasirmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Merle</td>
      <td role="cell">Wiegand</td>
      <td data-value="-908064000000" role="cell" class="epp-ar">1941-03-24</td>
      <td role="cell">Bartellchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Adam</td>
      <td role="cell">Huel</td>
      <td data-value="1068768000000" role="cell" class="epp-ar">2003-11-14</td>
      <td role="cell">Gissellemouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Blake</td>
      <td role="cell">Hauck</td>
      <td data-value="-1490486400000" role="cell" class="epp-ar">1922-10-09</td>
      <td role="cell">South Spencertown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Haskell</td>
      <td role="cell">Friesen</td>
      <td data-value="-251164800000" role="cell" class="epp-ar">1962-01-16</td>
      <td role="cell">South Marionhaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Rosetta</td>
      <td role="cell">Braun</td>
      <td data-value="-188179200000" role="cell" class="epp-ar">1964-01-15</td>
      <td role="cell">Reingerview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Vaughn</td>
      <td role="cell">Labadie</td>
      <td data-value="976233600000" role="cell" class="epp-ar">2000-12-08</td>
      <td role="cell">VonRuedenville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Gayle</td>
      <td role="cell">Brown</td>
      <td data-value="593913600000" role="cell" class="epp-ar">1988-10-27</td>
      <td role="cell">North Myrna</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Gillian</td>
      <td role="cell">Yundt</td>
      <td data-value="1283212800000" role="cell" class="epp-ar">2010-08-31</td>
      <td role="cell">Boehmland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Micheal</td>
      <td role="cell">Kreiger</td>
      <td data-value="-146793600000" role="cell" class="epp-ar">1965-05-08</td>
      <td role="cell">West Estellaview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Lauren</td>
      <td role="cell">Wolf</td>
      <td data-value="-769737600000" role="cell" class="epp-ar">1945-08-11</td>
      <td role="cell">Port Winfieldberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Marlen</td>
      <td role="cell">Schaden</td>
      <td data-value="1477526400000" role="cell" class="epp-ar">2016-10-27</td>
      <td role="cell">Port Alvenabury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Verner</td>
      <td role="cell">McLaughlin</td>
      <td data-value="671760000000" role="cell" class="epp-ar">1991-04-16</td>
      <td role="cell">North Myatown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Lilliana</td>
      <td role="cell">Romaguera</td>
      <td data-value="-1042502400000" role="cell" class="epp-ar">1936-12-19</td>
      <td role="cell">West Blaze</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Janae</td>
      <td role="cell">Ondricka</td>
      <td data-value="-1428278400000" role="cell" class="epp-ar">1924-09-28</td>
      <td role="cell">South Rocky</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Leilani</td>
      <td role="cell">Macejkovic</td>
      <td data-value="-912470400000" role="cell" class="epp-ar">1941-02-01</td>
      <td role="cell">Lake Burnice</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Janick</td>
      <td role="cell">King</td>
      <td data-value="314064000000" role="cell" class="epp-ar">1979-12-15</td>
      <td role="cell">North Giovaniland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Ulices</td>
      <td role="cell">Johnson</td>
      <td data-value="1664323200000" role="cell" class="epp-ar">2022-09-28</td>
      <td role="cell">Wolffside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Kitty</td>
      <td role="cell">Medhurst</td>
      <td data-value="-1823212800000" role="cell" class="epp-ar">1912-03-24</td>
      <td role="cell">Lake Kaylee</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Raymundo</td>
      <td role="cell">Mann</td>
      <td data-value="-662169600000" role="cell" class="epp-ar">1949-01-07</td>
      <td role="cell">Port Maynard</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Angelica</td>
      <td role="cell">Marquardt</td>
      <td data-value="-91497600000" role="cell" class="epp-ar">1967-02-07</td>
      <td role="cell">Evansmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Britney</td>
      <td role="cell">Koepp</td>
      <td data-value="790300800000" role="cell" class="epp-ar">1995-01-17</td>
      <td role="cell">South Loma</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Cecil</td>
      <td role="cell">Hartmann</td>
      <td data-value="-1579478400000" role="cell" class="epp-ar">1919-12-14</td>
      <td role="cell">Lorafurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Sigmund</td>
      <td role="cell">Prohaska</td>
      <td data-value="21340800000" role="cell" class="epp-ar">1970-09-05</td>
      <td role="cell">Lourdesport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Dino</td>
      <td role="cell">Romaguera</td>
      <td data-value="1187481600000" role="cell" class="epp-ar">2007-08-19</td>
      <td role="cell">Leannonshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Don</td>
      <td role="cell">Stiedemann</td>
      <td data-value="287712000000" role="cell" class="epp-ar">1979-02-13</td>
      <td role="cell">Americofurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Cicero</td>
      <td role="cell">Marquardt</td>
      <td data-value="-15552000000" role="cell" class="epp-ar">1969-07-05</td>
      <td role="cell">Johnstonshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Elna</td>
      <td role="cell">Bernier</td>
      <td data-value="-1564099200000" role="cell" class="epp-ar">1920-06-09</td>
      <td role="cell">Lednerstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Antonette</td>
      <td role="cell">Flatley</td>
      <td data-value="883008000000" role="cell" class="epp-ar">1997-12-25</td>
      <td role="cell">New Demondhaven</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;
}