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 Filomena Douglas 1939-01-22 New Jamaal
England Trycia Marquardt 1964-01-12 North Delphia
Scotland Lafayette Zulauf 1957-07-21 New Elza
Northern Ireland Douglas Bartell 1917-10-05 Jadynburgh
Northern Ireland Austin Okuneva 1976-07-29 Port Mandyburgh
England Mireya Borer 1944-07-04 South Elsemouth
Wales Vivian Donnelly 1999-03-15 Nayeliview
England Orie Keeling 2008-09-06 South Casimer
England Jerad Farrell 1963-01-06 Zacherychester
Scotland Kamryn Kessler 1936-10-02 Russelberg
Northern Ireland Augustine Halvorson 1970-08-12 East Marionburgh
England Bette Dicki 1912-02-02 New Augustus
Wales Nola Bailey 1993-10-23 East Carolyn
England Penelope Grady 1966-12-14 Patsychester
England Javonte Cronin 1964-10-14 Bergeview
England Allene Aufderhar 1965-02-06 Lake Aron
Wales Danny Koepp 2002-01-25 New Daniella
Northern Ireland Boyd Tremblay 1998-02-07 West Hazle
Northern Ireland Gayle Hickle 2008-01-07 North Kaileetown
Wales Foster Lueilwitz 1982-02-22 North Billieborough
England Belle Little 2010-03-10 Selenatown
Scotland Marcel Koelpin 1963-12-20 South Vanessatown
Scotland Annabel Walsh 1964-07-08 North Carrollchester
Scotland Lucie Kassulke 1938-06-15 Jacobishire
Wales Hollis Weissnat 1973-01-12 Port Mariahfort
Wales Lawson Kuhic 2012-08-25 Schinnerchester
Wales Nannie Cremin 1964-10-20 South Lilian
Scotland Anabel McClure 1917-07-01 New Laverneton
Northern Ireland Izaiah Prosacco 1996-05-13 Zeldafort
Scotland Hilda O'Keefe 1924-11-04 North Vidal
Scotland Zella Sanford 1992-06-30 Verlahaven
England Ramiro Terry 1962-11-19 Stiedemannville
England Rylee Hodkiewicz 2019-05-01 North Jorgemouth
England Elyse Casper 1924-03-10 East Alanna
Wales Rashawn Okuneva 1942-03-12 Langworthton
England Maria Nicolas 1964-10-25 Holdentown
Wales Eva Dooley 2002-01-25 Mitchellland
Scotland Angelo Wunsch 1991-01-09 Elliotttown
England Sheridan Kutch 1993-06-30 New Tinamouth
Wales Ernesto Heidenreich 1982-04-02 East Lora
Northern Ireland Dock Spencer 1951-05-21 Leliamouth
Scotland Kyla Mayert 2020-08-04 McKenziefort
Northern Ireland Emiliano Grimes 2003-02-23 Manteberg
Wales Magali Towne 1944-05-07 North Nathenstad
Scotland Ambrose Green 1969-12-08 East Peterton
England Mohamed Kuvalis 1939-11-20 North Cole
England Julian Osinski 1994-11-09 Othochester
Wales Filomena Keeling 1972-06-10 South Lue
Scotland Danial Williamson 1992-03-09 Streichtown
Wales Vincenzo Trantow 1956-12-30 New Blanche

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">Filomena</td>
      <td role="cell">Douglas</td>
      <td data-value="-976492800000" role="cell" class="epp-ar">1939-01-22</td>
      <td role="cell">New Jamaal</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Trycia</td>
      <td role="cell">Marquardt</td>
      <td data-value="-188438400000" role="cell" class="epp-ar">1964-01-12</td>
      <td role="cell">North Delphia</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Lafayette</td>
      <td role="cell">Zulauf</td>
      <td data-value="-392860800000" role="cell" class="epp-ar">1957-07-21</td>
      <td role="cell">New Elza</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Douglas</td>
      <td role="cell">Bartell</td>
      <td data-value="-1648598400000" role="cell" class="epp-ar">1917-10-05</td>
      <td role="cell">Jadynburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Austin</td>
      <td role="cell">Okuneva</td>
      <td data-value="207446400000" role="cell" class="epp-ar">1976-07-29</td>
      <td role="cell">Port Mandyburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Mireya</td>
      <td role="cell">Borer</td>
      <td data-value="-804556800000" role="cell" class="epp-ar">1944-07-04</td>
      <td role="cell">South Elsemouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Vivian</td>
      <td role="cell">Donnelly</td>
      <td data-value="921456000000" role="cell" class="epp-ar">1999-03-15</td>
      <td role="cell">Nayeliview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Orie</td>
      <td role="cell">Keeling</td>
      <td data-value="1220659200000" role="cell" class="epp-ar">2008-09-06</td>
      <td role="cell">South Casimer</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Jerad</td>
      <td role="cell">Farrell</td>
      <td data-value="-220492800000" role="cell" class="epp-ar">1963-01-06</td>
      <td role="cell">Zacherychester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Kamryn</td>
      <td role="cell">Kessler</td>
      <td data-value="-1049241600000" role="cell" class="epp-ar">1936-10-02</td>
      <td role="cell">Russelberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Augustine</td>
      <td role="cell">Halvorson</td>
      <td data-value="19267200000" role="cell" class="epp-ar">1970-08-12</td>
      <td role="cell">East Marionburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Bette</td>
      <td role="cell">Dicki</td>
      <td data-value="-1827619200000" role="cell" class="epp-ar">1912-02-02</td>
      <td role="cell">New Augustus</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Nola</td>
      <td role="cell">Bailey</td>
      <td data-value="751334400000" role="cell" class="epp-ar">1993-10-23</td>
      <td role="cell">East Carolyn</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Penelope</td>
      <td role="cell">Grady</td>
      <td data-value="-96249600000" role="cell" class="epp-ar">1966-12-14</td>
      <td role="cell">Patsychester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Javonte</td>
      <td role="cell">Cronin</td>
      <td data-value="-164592000000" role="cell" class="epp-ar">1964-10-14</td>
      <td role="cell">Bergeview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Allene</td>
      <td role="cell">Aufderhar</td>
      <td data-value="-154656000000" role="cell" class="epp-ar">1965-02-06</td>
      <td role="cell">Lake Aron</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Danny</td>
      <td role="cell">Koepp</td>
      <td data-value="1011916800000" role="cell" class="epp-ar">2002-01-25</td>
      <td role="cell">New Daniella</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Boyd</td>
      <td role="cell">Tremblay</td>
      <td data-value="886809600000" role="cell" class="epp-ar">1998-02-07</td>
      <td role="cell">West Hazle</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Gayle</td>
      <td role="cell">Hickle</td>
      <td data-value="1199664000000" role="cell" class="epp-ar">2008-01-07</td>
      <td role="cell">North Kaileetown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Foster</td>
      <td role="cell">Lueilwitz</td>
      <td data-value="383184000000" role="cell" class="epp-ar">1982-02-22</td>
      <td role="cell">North Billieborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Belle</td>
      <td role="cell">Little</td>
      <td data-value="1268179200000" role="cell" class="epp-ar">2010-03-10</td>
      <td role="cell">Selenatown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Marcel</td>
      <td role="cell">Koelpin</td>
      <td data-value="-190425600000" role="cell" class="epp-ar">1963-12-20</td>
      <td role="cell">South Vanessatown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Annabel</td>
      <td role="cell">Walsh</td>
      <td data-value="-173059200000" role="cell" class="epp-ar">1964-07-08</td>
      <td role="cell">North Carrollchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Lucie</td>
      <td role="cell">Kassulke</td>
      <td data-value="-995587200000" role="cell" class="epp-ar">1938-06-15</td>
      <td role="cell">Jacobishire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Hollis</td>
      <td role="cell">Weissnat</td>
      <td data-value="95644800000" role="cell" class="epp-ar">1973-01-12</td>
      <td role="cell">Port Mariahfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Lawson</td>
      <td role="cell">Kuhic</td>
      <td data-value="1345852800000" role="cell" class="epp-ar">2012-08-25</td>
      <td role="cell">Schinnerchester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Nannie</td>
      <td role="cell">Cremin</td>
      <td data-value="-164073600000" role="cell" class="epp-ar">1964-10-20</td>
      <td role="cell">South Lilian</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Anabel</td>
      <td role="cell">McClure</td>
      <td data-value="-1656892800000" role="cell" class="epp-ar">1917-07-01</td>
      <td role="cell">New Laverneton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Izaiah</td>
      <td role="cell">Prosacco</td>
      <td data-value="831945600000" role="cell" class="epp-ar">1996-05-13</td>
      <td role="cell">Zeldafort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Hilda</td>
      <td role="cell">O'Keefe</td>
      <td data-value="-1425081600000" role="cell" class="epp-ar">1924-11-04</td>
      <td role="cell">North Vidal</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Zella</td>
      <td role="cell">Sanford</td>
      <td data-value="709862400000" role="cell" class="epp-ar">1992-06-30</td>
      <td role="cell">Verlahaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Ramiro</td>
      <td role="cell">Terry</td>
      <td data-value="-224640000000" role="cell" class="epp-ar">1962-11-19</td>
      <td role="cell">Stiedemannville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Rylee</td>
      <td role="cell">Hodkiewicz</td>
      <td data-value="1556668800000" role="cell" class="epp-ar">2019-05-01</td>
      <td role="cell">North Jorgemouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Elyse</td>
      <td role="cell">Casper</td>
      <td data-value="-1445731200000" role="cell" class="epp-ar">1924-03-10</td>
      <td role="cell">East Alanna</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Rashawn</td>
      <td role="cell">Okuneva</td>
      <td data-value="-877564800000" role="cell" class="epp-ar">1942-03-12</td>
      <td role="cell">Langworthton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Maria</td>
      <td role="cell">Nicolas</td>
      <td data-value="-163641600000" role="cell" class="epp-ar">1964-10-25</td>
      <td role="cell">Holdentown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Eva</td>
      <td role="cell">Dooley</td>
      <td data-value="1011916800000" role="cell" class="epp-ar">2002-01-25</td>
      <td role="cell">Mitchellland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Angelo</td>
      <td role="cell">Wunsch</td>
      <td data-value="663379200000" role="cell" class="epp-ar">1991-01-09</td>
      <td role="cell">Elliotttown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Sheridan</td>
      <td role="cell">Kutch</td>
      <td data-value="741398400000" role="cell" class="epp-ar">1993-06-30</td>
      <td role="cell">New Tinamouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Ernesto</td>
      <td role="cell">Heidenreich</td>
      <td data-value="386553600000" role="cell" class="epp-ar">1982-04-02</td>
      <td role="cell">East Lora</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Dock</td>
      <td role="cell">Spencer</td>
      <td data-value="-587520000000" role="cell" class="epp-ar">1951-05-21</td>
      <td role="cell">Leliamouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Kyla</td>
      <td role="cell">Mayert</td>
      <td data-value="1596499200000" role="cell" class="epp-ar">2020-08-04</td>
      <td role="cell">McKenziefort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Emiliano</td>
      <td role="cell">Grimes</td>
      <td data-value="1045958400000" role="cell" class="epp-ar">2003-02-23</td>
      <td role="cell">Manteberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Magali</td>
      <td role="cell">Towne</td>
      <td data-value="-809568000000" role="cell" class="epp-ar">1944-05-07</td>
      <td role="cell">North Nathenstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Ambrose</td>
      <td role="cell">Green</td>
      <td data-value="-2073600000" role="cell" class="epp-ar">1969-12-08</td>
      <td role="cell">East Peterton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Mohamed</td>
      <td role="cell">Kuvalis</td>
      <td data-value="-950400000000" role="cell" class="epp-ar">1939-11-20</td>
      <td role="cell">North Cole</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Julian</td>
      <td role="cell">Osinski</td>
      <td data-value="784339200000" role="cell" class="epp-ar">1994-11-09</td>
      <td role="cell">Othochester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Filomena</td>
      <td role="cell">Keeling</td>
      <td data-value="76982400000" role="cell" class="epp-ar">1972-06-10</td>
      <td role="cell">South Lue</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Danial</td>
      <td role="cell">Williamson</td>
      <td data-value="700099200000" role="cell" class="epp-ar">1992-03-09</td>
      <td role="cell">Streichtown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Vincenzo</td>
      <td role="cell">Trantow</td>
      <td data-value="-410400000000" role="cell" class="epp-ar">1956-12-30</td>
      <td role="cell">New Blanche</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;
}