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 Coleman Johns 1947-01-19 Kohlerton
Northern Ireland Lilla Wilkinson 1969-10-31 Robelfort
Scotland Alejandrin Zboncak 1971-07-10 Adelineport
Wales Sheila Schneider 2005-12-02 East Valentinemouth
Wales Alayna Streich 1957-12-23 Port Jett
Wales Ashlynn Stokes 1964-07-18 Gerardmouth
Wales Brent Stokes 1969-05-14 Sebastianstad
Scotland Kurt Rempel 1996-07-25 Daughertyside
Scotland Jayson Hoeger 1990-04-04 Lake Roselynfurt
Wales Rosamond Rodriguez 1964-04-01 Willmsshire
Scotland Gunnar Keeling 1964-05-03 West Frederick
Scotland Avery Romaguera 1935-03-19 Marcosside
England Cleve Pollich 1960-04-22 Cristtown
England Retta Abbott 2008-01-23 Paigeborough
Scotland Derick Homenick 1999-04-22 Port Ameliastad
Scotland Nelda Dicki 1964-03-08 Feilshire
Scotland Enola Ernser 1956-10-01 Port Stuartberg
Northern Ireland Mafalda Thiel 1997-05-03 Ewellmouth
Scotland Jocelyn Hessel 1963-11-29 Moshechester
Scotland Shany Stanton 2010-04-12 Lake Ernestoshire
England Gardner Howe 1988-03-24 West Winfieldville
Wales Eino Zemlak 1957-12-09 Minachester
Northern Ireland Reba Huel 1929-01-08 Albertport
England Rocky Miller 1915-06-02 East Francisco
England Al Mitchell 1947-04-04 Chelseastad
Northern Ireland Caden Monahan 1969-03-14 Lake Geraldine
England Pauline Weissnat 1909-08-04 East Earlton
Wales Iva Terry 1977-12-27 Shaneltown
Northern Ireland Otho Skiles 1989-08-29 West Cornellville
England Aracely Howe 2003-01-30 New Xanderland
Wales Glen Gusikowski 1972-04-21 Maeganfort
Northern Ireland Celine Toy 1935-11-22 Bernierborough
Northern Ireland Marielle Kris 1979-04-12 Milesside
Wales Demetrius Kutch 1964-06-01 Port Kelsi
Northern Ireland Addison Hudson 1979-08-26 West Jaylen
Northern Ireland Alexane Homenick 1998-05-26 Lake Barrett
Scotland Jevon Braun 1964-07-09 Hermannbury
Scotland Kane Kris 1932-02-04 New Irma
Scotland Ezra Pfannerstill 1944-01-22 Port Dinabury
England Crawford Schaden 1964-03-23 Port Rae
Northern Ireland Mariam Daniel 1964-07-22 Port Eugenemouth
England Dock Ullrich 1964-08-16 O'Keefeshire
Wales Tomas Buckridge 1984-05-29 West Damien
Wales Enos Glover 2000-11-01 East Felicity
Wales Mertie Haley 1992-03-25 Lake Leobury
Wales Marianna O'Hara 1970-12-21 Bonniefort
Wales Jovani Rohan 1973-07-30 Titoville
Northern Ireland Olen Ankunding 1964-06-01 South Davonte
Scotland Trudie Gottlieb 1946-12-12 North Trevion
England Christa Heaney 1965-10-21 South Ewaldport

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">Coleman</td>
      <td role="cell">Johns</td>
      <td data-value="-724291200000" role="cell" class="epp-ar">1947-01-19</td>
      <td role="cell">Kohlerton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Lilla</td>
      <td role="cell">Wilkinson</td>
      <td data-value="-5356800000" role="cell" class="epp-ar">1969-10-31</td>
      <td role="cell">Robelfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Alejandrin</td>
      <td role="cell">Zboncak</td>
      <td data-value="47952000000" role="cell" class="epp-ar">1971-07-10</td>
      <td role="cell">Adelineport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Sheila</td>
      <td role="cell">Schneider</td>
      <td data-value="1133481600000" role="cell" class="epp-ar">2005-12-02</td>
      <td role="cell">East Valentinemouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Alayna</td>
      <td role="cell">Streich</td>
      <td data-value="-379468800000" role="cell" class="epp-ar">1957-12-23</td>
      <td role="cell">Port Jett</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Ashlynn</td>
      <td role="cell">Stokes</td>
      <td data-value="-172195200000" role="cell" class="epp-ar">1964-07-18</td>
      <td role="cell">Gerardmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Brent</td>
      <td role="cell">Stokes</td>
      <td data-value="-20044800000" role="cell" class="epp-ar">1969-05-14</td>
      <td role="cell">Sebastianstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Kurt</td>
      <td role="cell">Rempel</td>
      <td data-value="838252800000" role="cell" class="epp-ar">1996-07-25</td>
      <td role="cell">Daughertyside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jayson</td>
      <td role="cell">Hoeger</td>
      <td data-value="639187200000" role="cell" class="epp-ar">1990-04-04</td>
      <td role="cell">Lake Roselynfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Rosamond</td>
      <td role="cell">Rodriguez</td>
      <td data-value="-181526400000" role="cell" class="epp-ar">1964-04-01</td>
      <td role="cell">Willmsshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Gunnar</td>
      <td role="cell">Keeling</td>
      <td data-value="-178761600000" role="cell" class="epp-ar">1964-05-03</td>
      <td role="cell">West Frederick</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Avery</td>
      <td role="cell">Romaguera</td>
      <td data-value="-1097884800000" role="cell" class="epp-ar">1935-03-19</td>
      <td role="cell">Marcosside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Cleve</td>
      <td role="cell">Pollich</td>
      <td data-value="-305942400000" role="cell" class="epp-ar">1960-04-22</td>
      <td role="cell">Cristtown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Retta</td>
      <td role="cell">Abbott</td>
      <td data-value="1201046400000" role="cell" class="epp-ar">2008-01-23</td>
      <td role="cell">Paigeborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Derick</td>
      <td role="cell">Homenick</td>
      <td data-value="924739200000" role="cell" class="epp-ar">1999-04-22</td>
      <td role="cell">Port Ameliastad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Nelda</td>
      <td role="cell">Dicki</td>
      <td data-value="-183600000000" role="cell" class="epp-ar">1964-03-08</td>
      <td role="cell">Feilshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Enola</td>
      <td role="cell">Ernser</td>
      <td data-value="-418176000000" role="cell" class="epp-ar">1956-10-01</td>
      <td role="cell">Port Stuartberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Mafalda</td>
      <td role="cell">Thiel</td>
      <td data-value="862617600000" role="cell" class="epp-ar">1997-05-03</td>
      <td role="cell">Ewellmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jocelyn</td>
      <td role="cell">Hessel</td>
      <td data-value="-192240000000" role="cell" class="epp-ar">1963-11-29</td>
      <td role="cell">Moshechester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Shany</td>
      <td role="cell">Stanton</td>
      <td data-value="1271030400000" role="cell" class="epp-ar">2010-04-12</td>
      <td role="cell">Lake Ernestoshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Gardner</td>
      <td role="cell">Howe</td>
      <td data-value="575164800000" role="cell" class="epp-ar">1988-03-24</td>
      <td role="cell">West Winfieldville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Eino</td>
      <td role="cell">Zemlak</td>
      <td data-value="-380678400000" role="cell" class="epp-ar">1957-12-09</td>
      <td role="cell">Minachester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Reba</td>
      <td role="cell">Huel</td>
      <td data-value="-1293235200000" role="cell" class="epp-ar">1929-01-08</td>
      <td role="cell">Albertport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Rocky</td>
      <td role="cell">Miller</td>
      <td data-value="-1722556800000" role="cell" class="epp-ar">1915-06-02</td>
      <td role="cell">East Francisco</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Al</td>
      <td role="cell">Mitchell</td>
      <td data-value="-717811200000" role="cell" class="epp-ar">1947-04-04</td>
      <td role="cell">Chelseastad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Caden</td>
      <td role="cell">Monahan</td>
      <td data-value="-25315200000" role="cell" class="epp-ar">1969-03-14</td>
      <td role="cell">Lake Geraldine</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Pauline</td>
      <td role="cell">Weissnat</td>
      <td data-value="-1906416000000" role="cell" class="epp-ar">1909-08-04</td>
      <td role="cell">East Earlton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Iva</td>
      <td role="cell">Terry</td>
      <td data-value="252028800000" role="cell" class="epp-ar">1977-12-27</td>
      <td role="cell">Shaneltown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Otho</td>
      <td role="cell">Skiles</td>
      <td data-value="620352000000" role="cell" class="epp-ar">1989-08-29</td>
      <td role="cell">West Cornellville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Aracely</td>
      <td role="cell">Howe</td>
      <td data-value="1043884800000" role="cell" class="epp-ar">2003-01-30</td>
      <td role="cell">New Xanderland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Glen</td>
      <td role="cell">Gusikowski</td>
      <td data-value="72662400000" role="cell" class="epp-ar">1972-04-21</td>
      <td role="cell">Maeganfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Celine</td>
      <td role="cell">Toy</td>
      <td data-value="-1076457600000" role="cell" class="epp-ar">1935-11-22</td>
      <td role="cell">Bernierborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Marielle</td>
      <td role="cell">Kris</td>
      <td data-value="292723200000" role="cell" class="epp-ar">1979-04-12</td>
      <td role="cell">Milesside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Demetrius</td>
      <td role="cell">Kutch</td>
      <td data-value="-176256000000" role="cell" class="epp-ar">1964-06-01</td>
      <td role="cell">Port Kelsi</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Addison</td>
      <td role="cell">Hudson</td>
      <td data-value="304473600000" role="cell" class="epp-ar">1979-08-26</td>
      <td role="cell">West Jaylen</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Alexane</td>
      <td role="cell">Homenick</td>
      <td data-value="896140800000" role="cell" class="epp-ar">1998-05-26</td>
      <td role="cell">Lake Barrett</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jevon</td>
      <td role="cell">Braun</td>
      <td data-value="-172972800000" role="cell" class="epp-ar">1964-07-09</td>
      <td role="cell">Hermannbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Kane</td>
      <td role="cell">Kris</td>
      <td data-value="-1196294400000" role="cell" class="epp-ar">1932-02-04</td>
      <td role="cell">New Irma</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Ezra</td>
      <td role="cell">Pfannerstill</td>
      <td data-value="-818726400000" role="cell" class="epp-ar">1944-01-22</td>
      <td role="cell">Port Dinabury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Crawford</td>
      <td role="cell">Schaden</td>
      <td data-value="-182304000000" role="cell" class="epp-ar">1964-03-23</td>
      <td role="cell">Port Rae</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Mariam</td>
      <td role="cell">Daniel</td>
      <td data-value="-171849600000" role="cell" class="epp-ar">1964-07-22</td>
      <td role="cell">Port Eugenemouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Dock</td>
      <td role="cell">Ullrich</td>
      <td data-value="-169689600000" role="cell" class="epp-ar">1964-08-16</td>
      <td role="cell">O'Keefeshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Tomas</td>
      <td role="cell">Buckridge</td>
      <td data-value="454636800000" role="cell" class="epp-ar">1984-05-29</td>
      <td role="cell">West Damien</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Enos</td>
      <td role="cell">Glover</td>
      <td data-value="973036800000" role="cell" class="epp-ar">2000-11-01</td>
      <td role="cell">East Felicity</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Mertie</td>
      <td role="cell">Haley</td>
      <td data-value="701481600000" role="cell" class="epp-ar">1992-03-25</td>
      <td role="cell">Lake Leobury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Marianna</td>
      <td role="cell">O'Hara</td>
      <td data-value="30585600000" role="cell" class="epp-ar">1970-12-21</td>
      <td role="cell">Bonniefort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Jovani</td>
      <td role="cell">Rohan</td>
      <td data-value="112838400000" role="cell" class="epp-ar">1973-07-30</td>
      <td role="cell">Titoville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Olen</td>
      <td role="cell">Ankunding</td>
      <td data-value="-176256000000" role="cell" class="epp-ar">1964-06-01</td>
      <td role="cell">South Davonte</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Trudie</td>
      <td role="cell">Gottlieb</td>
      <td data-value="-727574400000" role="cell" class="epp-ar">1946-12-12</td>
      <td role="cell">North Trevion</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Christa</td>
      <td role="cell">Heaney</td>
      <td data-value="-132451200000" role="cell" class="epp-ar">1965-10-21</td>
      <td role="cell">South Ewaldport</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;
}