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 Liliane Pouros 1970-11-02 Port Ismael
Northern Ireland Aliza Powlowski 1963-12-10 Shieldstown
Scotland Madeline O'Reilly 1998-02-05 New Eldred
Northern Ireland Guido Kunze 1970-08-16 West Jacquelyn
Scotland Maxie Murphy 1948-09-08 Francescabury
Northern Ireland Filomena Cummings 1934-03-21 Sheridanfurt
Scotland Birdie Gutmann 1999-10-24 North Aimee
Scotland Fannie Watsica 1998-09-16 West Johannaton
Northern Ireland Gertrude Mills 1936-04-19 Hettingerview
England Pamela Morar 1931-09-20 East Kaileechester
Scotland Lue Auer 1923-08-11 East Dasia
Wales Eileen Gerhold 2000-01-11 East Angelinaland
Northern Ireland Virginia Weber 1968-11-14 Schowalterfort
England Lacy Goodwin 1990-04-27 Eltonland
Scotland Chadrick Torp 1993-03-30 Satterfieldland
Northern Ireland Jannie Tremblay 1989-12-16 New Khalil
Scotland Alta Zieme 1903-09-22 Lizzieview
Northern Ireland Freddy Schaefer 1917-11-10 Gunnerburgh
Wales Winston Bruen 1938-01-06 Delphineshire
Wales Melvina Herman 2017-11-17 North Erick
Scotland Herta Hirthe 2002-11-24 South Noble
Wales Lora Crona 1999-09-30 Inesport
Wales Micheal Beatty 1924-02-13 Port Aurelio
Wales Kariane Altenwerth 1964-01-01 Maverickton
Scotland Jalyn Murazik 1969-11-01 New Daija
Northern Ireland Antonetta Stamm 1979-10-21 Weberview
England Sasha Schuppe 1992-07-18 Port Aurelialand
England Stephan Gusikowski 1964-02-25 East Newell
Northern Ireland Dorris Herman 1925-07-15 Port Abrahamstad
Scotland Lonie Harber 2018-11-14 South Henderson
England Mariana Rosenbaum 1991-05-15 East Jordynside
England Pablo Wyman 1927-08-31 New Margarete
England Presley McKenzie 1921-03-22 New Kenton
Scotland Kody Bernhard 1948-11-09 Lake Lamonttown
England Lennie Cremin 1991-07-29 West Enrique
Wales Delphia Trantow 1951-01-02 Vivianeland
Wales Roslyn Ebert 1958-09-08 West Pearlineton
Northern Ireland Viola Dickinson 1908-12-24 South Ahmad
England Blair Kemmer 1991-04-19 South Domingoville
Northern Ireland Dane Hane 1994-03-08 South Chance
Wales Gregory Murazik 1955-12-04 Johnstonport
Wales Claudie Windler 1981-06-23 Aldaborough
Wales Malinda Zboncak 1982-11-03 Osinskiton
England Rosalind Brakus 1952-04-28 Lake Anaborough
Northern Ireland Vinnie Altenwerth 1984-08-23 Flatleymouth
Scotland Mellie Schowalter 1963-12-06 Cartwrightland
England Eva Hahn 1986-06-09 Ricemouth
Northern Ireland Maud Wehner 1954-01-09 Irwinport
England Roberta Goodwin 1946-12-27 Port Piper
Northern Ireland Quinton Swift 2000-07-29 North Gretchenfort

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">Liliane</td>
      <td role="cell">Pouros</td>
      <td data-value="26352000000" role="cell" class="epp-ar">1970-11-02</td>
      <td role="cell">Port Ismael</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Aliza</td>
      <td role="cell">Powlowski</td>
      <td data-value="-191289600000" role="cell" class="epp-ar">1963-12-10</td>
      <td role="cell">Shieldstown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Madeline</td>
      <td role="cell">O'Reilly</td>
      <td data-value="886636800000" role="cell" class="epp-ar">1998-02-05</td>
      <td role="cell">New Eldred</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Guido</td>
      <td role="cell">Kunze</td>
      <td data-value="19612800000" role="cell" class="epp-ar">1970-08-16</td>
      <td role="cell">West Jacquelyn</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Maxie</td>
      <td role="cell">Murphy</td>
      <td data-value="-672624000000" role="cell" class="epp-ar">1948-09-08</td>
      <td role="cell">Francescabury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Filomena</td>
      <td role="cell">Cummings</td>
      <td data-value="-1129248000000" role="cell" class="epp-ar">1934-03-21</td>
      <td role="cell">Sheridanfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Birdie</td>
      <td role="cell">Gutmann</td>
      <td data-value="940723200000" role="cell" class="epp-ar">1999-10-24</td>
      <td role="cell">North Aimee</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Fannie</td>
      <td role="cell">Watsica</td>
      <td data-value="905904000000" role="cell" class="epp-ar">1998-09-16</td>
      <td role="cell">West Johannaton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Gertrude</td>
      <td role="cell">Mills</td>
      <td data-value="-1063584000000" role="cell" class="epp-ar">1936-04-19</td>
      <td role="cell">Hettingerview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Pamela</td>
      <td role="cell">Morar</td>
      <td data-value="-1208131200000" role="cell" class="epp-ar">1931-09-20</td>
      <td role="cell">East Kaileechester</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Lue</td>
      <td role="cell">Auer</td>
      <td data-value="-1464048000000" role="cell" class="epp-ar">1923-08-11</td>
      <td role="cell">East Dasia</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Eileen</td>
      <td role="cell">Gerhold</td>
      <td data-value="947548800000" role="cell" class="epp-ar">2000-01-11</td>
      <td role="cell">East Angelinaland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Virginia</td>
      <td role="cell">Weber</td>
      <td data-value="-35683200000" role="cell" class="epp-ar">1968-11-14</td>
      <td role="cell">Schowalterfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Lacy</td>
      <td role="cell">Goodwin</td>
      <td data-value="641174400000" role="cell" class="epp-ar">1990-04-27</td>
      <td role="cell">Eltonland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Chadrick</td>
      <td role="cell">Torp</td>
      <td data-value="733449600000" role="cell" class="epp-ar">1993-03-30</td>
      <td role="cell">Satterfieldland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jannie</td>
      <td role="cell">Tremblay</td>
      <td data-value="629769600000" role="cell" class="epp-ar">1989-12-16</td>
      <td role="cell">New Khalil</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Alta</td>
      <td role="cell">Zieme</td>
      <td data-value="-2091571200000" role="cell" class="epp-ar">1903-09-22</td>
      <td role="cell">Lizzieview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Freddy</td>
      <td role="cell">Schaefer</td>
      <td data-value="-1645488000000" role="cell" class="epp-ar">1917-11-10</td>
      <td role="cell">Gunnerburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Winston</td>
      <td role="cell">Bruen</td>
      <td data-value="-1009411200000" role="cell" class="epp-ar">1938-01-06</td>
      <td role="cell">Delphineshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Melvina</td>
      <td role="cell">Herman</td>
      <td data-value="1510876800000" role="cell" class="epp-ar">2017-11-17</td>
      <td role="cell">North Erick</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Herta</td>
      <td role="cell">Hirthe</td>
      <td data-value="1038096000000" role="cell" class="epp-ar">2002-11-24</td>
      <td role="cell">South Noble</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Lora</td>
      <td role="cell">Crona</td>
      <td data-value="938649600000" role="cell" class="epp-ar">1999-09-30</td>
      <td role="cell">Inesport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Micheal</td>
      <td role="cell">Beatty</td>
      <td data-value="-1447977600000" role="cell" class="epp-ar">1924-02-13</td>
      <td role="cell">Port Aurelio</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Kariane</td>
      <td role="cell">Altenwerth</td>
      <td data-value="-189388800000" role="cell" class="epp-ar">1964-01-01</td>
      <td role="cell">Maverickton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jalyn</td>
      <td role="cell">Murazik</td>
      <td data-value="-5270400000" role="cell" class="epp-ar">1969-11-01</td>
      <td role="cell">New Daija</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Antonetta</td>
      <td role="cell">Stamm</td>
      <td data-value="309312000000" role="cell" class="epp-ar">1979-10-21</td>
      <td role="cell">Weberview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Sasha</td>
      <td role="cell">Schuppe</td>
      <td data-value="711417600000" role="cell" class="epp-ar">1992-07-18</td>
      <td role="cell">Port Aurelialand</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Stephan</td>
      <td role="cell">Gusikowski</td>
      <td data-value="-184636800000" role="cell" class="epp-ar">1964-02-25</td>
      <td role="cell">East Newell</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Dorris</td>
      <td role="cell">Herman</td>
      <td data-value="-1403222400000" role="cell" class="epp-ar">1925-07-15</td>
      <td role="cell">Port Abrahamstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Lonie</td>
      <td role="cell">Harber</td>
      <td data-value="1542153600000" role="cell" class="epp-ar">2018-11-14</td>
      <td role="cell">South Henderson</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Mariana</td>
      <td role="cell">Rosenbaum</td>
      <td data-value="674265600000" role="cell" class="epp-ar">1991-05-15</td>
      <td role="cell">East Jordynside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Pablo</td>
      <td role="cell">Wyman</td>
      <td data-value="-1336089600000" role="cell" class="epp-ar">1927-08-31</td>
      <td role="cell">New Margarete</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Presley</td>
      <td role="cell">McKenzie</td>
      <td data-value="-1539388800000" role="cell" class="epp-ar">1921-03-22</td>
      <td role="cell">New Kenton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Kody</td>
      <td role="cell">Bernhard</td>
      <td data-value="-667267200000" role="cell" class="epp-ar">1948-11-09</td>
      <td role="cell">Lake Lamonttown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Lennie</td>
      <td role="cell">Cremin</td>
      <td data-value="680745600000" role="cell" class="epp-ar">1991-07-29</td>
      <td role="cell">West Enrique</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Delphia</td>
      <td role="cell">Trantow</td>
      <td data-value="-599529600000" role="cell" class="epp-ar">1951-01-02</td>
      <td role="cell">Vivianeland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Roslyn</td>
      <td role="cell">Ebert</td>
      <td data-value="-357091200000" role="cell" class="epp-ar">1958-09-08</td>
      <td role="cell">West Pearlineton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Viola</td>
      <td role="cell">Dickinson</td>
      <td data-value="-1925683200000" role="cell" class="epp-ar">1908-12-24</td>
      <td role="cell">South Ahmad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Blair</td>
      <td role="cell">Kemmer</td>
      <td data-value="672019200000" role="cell" class="epp-ar">1991-04-19</td>
      <td role="cell">South Domingoville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Dane</td>
      <td role="cell">Hane</td>
      <td data-value="763084800000" role="cell" class="epp-ar">1994-03-08</td>
      <td role="cell">South Chance</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Gregory</td>
      <td role="cell">Murazik</td>
      <td data-value="-444268800000" role="cell" class="epp-ar">1955-12-04</td>
      <td role="cell">Johnstonport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Claudie</td>
      <td role="cell">Windler</td>
      <td data-value="362102400000" role="cell" class="epp-ar">1981-06-23</td>
      <td role="cell">Aldaborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Malinda</td>
      <td role="cell">Zboncak</td>
      <td data-value="405129600000" role="cell" class="epp-ar">1982-11-03</td>
      <td role="cell">Osinskiton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Rosalind</td>
      <td role="cell">Brakus</td>
      <td data-value="-557884800000" role="cell" class="epp-ar">1952-04-28</td>
      <td role="cell">Lake Anaborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Vinnie</td>
      <td role="cell">Altenwerth</td>
      <td data-value="462067200000" role="cell" class="epp-ar">1984-08-23</td>
      <td role="cell">Flatleymouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Mellie</td>
      <td role="cell">Schowalter</td>
      <td data-value="-191635200000" role="cell" class="epp-ar">1963-12-06</td>
      <td role="cell">Cartwrightland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Eva</td>
      <td role="cell">Hahn</td>
      <td data-value="518659200000" role="cell" class="epp-ar">1986-06-09</td>
      <td role="cell">Ricemouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Maud</td>
      <td role="cell">Wehner</td>
      <td data-value="-504230400000" role="cell" class="epp-ar">1954-01-09</td>
      <td role="cell">Irwinport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Roberta</td>
      <td role="cell">Goodwin</td>
      <td data-value="-726278400000" role="cell" class="epp-ar">1946-12-27</td>
      <td role="cell">Port Piper</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Quinton</td>
      <td role="cell">Swift</td>
      <td data-value="964828800000" role="cell" class="epp-ar">2000-07-29</td>
      <td role="cell">North Gretchenfort</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;
}