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 Alfonzo Douglas 1921-10-15 Kaleighmouth
Northern Ireland Rebecca Wunsch 1921-04-10 Lake Dayana
Wales Stephany Rohan 1931-07-29 Padbergmouth
Wales Aleen Nitzsche 1955-05-20 South Althea
England Kirsten Ortiz 2013-12-06 Karianneside
England Amiya Rath 1989-02-10 New Marystad
England Godfrey Legros 1964-04-22 West Edgardomouth
Northern Ireland Augustine Abernathy 1926-08-31 South Jerrodhaven
Northern Ireland Janae Kessler 1944-01-12 Lake Judge
England Faustino Reichel 1961-05-09 North Tabithafort
Northern Ireland Arvilla McLaughlin 1967-11-20 Simonisland
Scotland Hollis Lehner 1969-11-24 Port Randyburgh
Northern Ireland Kenneth Powlowski 1960-03-14 West Jaquelinetown
Scotland Jettie Rohan 1981-08-01 Idellburgh
Scotland Bradley Fisher 1943-03-13 West Miguel
England Brook Kuhlman 1960-11-24 Lake Cleo
England Trystan Kerluke 1996-10-11 North Alexa
England Layne Nicolas 2017-05-09 Port Loyberg
Scotland Beaulah Berge 1991-12-28 West Luella
England Estevan Auer 1928-06-07 North Rodrick
Northern Ireland Jensen Gutmann 2006-05-06 Marvinfurt
England Frances Block 1955-07-15 West Winston
Northern Ireland Aurelie Koepp 1983-05-09 Kozeyport
Wales Maribel Johnston 1990-10-09 Pearlborough
Scotland Kaya Olson 1982-10-21 South Janisbury
Wales Wilfrid Reynolds 1992-09-29 North Salvatore
Wales Israel Paucek 1978-02-26 Gillianfurt
Northern Ireland Jon Koss 2020-01-02 Lake Gwendolynberg
Northern Ireland Lacey Blick 2000-04-23 Willview
Scotland Owen Denesik 1932-12-05 Riceside
Northern Ireland Kristoffer Mills 2003-06-06 North Kayleigh
Scotland Bethany Schinner 1953-12-09 South Garnetberg
Scotland Nya Corkery 2017-06-26 South Pearl
Scotland Emmanuel Senger 1969-08-31 Pietroberg
Northern Ireland Kole Corkery 1967-08-25 South Herman
Northern Ireland Cicero Kozey 1911-09-18 Port Narcisotown
England Alyson Mertz 1923-02-20 Lake Isaistad
England Christine Wiegand 2014-10-10 Flatleyville
Scotland Torey Harber 1920-05-30 Oberbrunnertown
Wales Javonte Morar 1945-02-14 Kuhicville
England Blanca Ullrich 1964-12-09 North Triston
Scotland Hans Maggio 1927-06-27 West Chloehaven
Wales Samara Hoeger 1964-04-14 South Doyle
Wales Vada Pouros 1954-02-27 Jacobsonville
Northern Ireland Mauricio Kihn 1904-05-25 Treverfurt
Scotland Orval Pfannerstill 1909-06-17 Macejkovicmouth
Northern Ireland Aliya Littel 1909-01-13 Jordimouth
England Everett Effertz 1937-08-16 Consuelobury
Wales Adrianna Hansen 1982-03-12 New Tomasaview
Northern Ireland William Erdman 1957-12-26 Kerlukefurt

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">Alfonzo</td>
      <td role="cell">Douglas</td>
      <td data-value="-1521504000000" role="cell" class="epp-ar">1921-10-15</td>
      <td role="cell">Kaleighmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Rebecca</td>
      <td role="cell">Wunsch</td>
      <td data-value="-1537747200000" role="cell" class="epp-ar">1921-04-10</td>
      <td role="cell">Lake Dayana</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Stephany</td>
      <td role="cell">Rohan</td>
      <td data-value="-1212710400000" role="cell" class="epp-ar">1931-07-29</td>
      <td role="cell">Padbergmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Aleen</td>
      <td role="cell">Nitzsche</td>
      <td data-value="-461376000000" role="cell" class="epp-ar">1955-05-20</td>
      <td role="cell">South Althea</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Kirsten</td>
      <td role="cell">Ortiz</td>
      <td data-value="1386288000000" role="cell" class="epp-ar">2013-12-06</td>
      <td role="cell">Karianneside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Amiya</td>
      <td role="cell">Rath</td>
      <td data-value="603072000000" role="cell" class="epp-ar">1989-02-10</td>
      <td role="cell">New Marystad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Godfrey</td>
      <td role="cell">Legros</td>
      <td data-value="-179712000000" role="cell" class="epp-ar">1964-04-22</td>
      <td role="cell">West Edgardomouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Augustine</td>
      <td role="cell">Abernathy</td>
      <td data-value="-1367625600000" role="cell" class="epp-ar">1926-08-31</td>
      <td role="cell">South Jerrodhaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Janae</td>
      <td role="cell">Kessler</td>
      <td data-value="-819590400000" role="cell" class="epp-ar">1944-01-12</td>
      <td role="cell">Lake Judge</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Faustino</td>
      <td role="cell">Reichel</td>
      <td data-value="-272937600000" role="cell" class="epp-ar">1961-05-09</td>
      <td role="cell">North Tabithafort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Arvilla</td>
      <td role="cell">McLaughlin</td>
      <td data-value="-66787200000" role="cell" class="epp-ar">1967-11-20</td>
      <td role="cell">Simonisland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Hollis</td>
      <td role="cell">Lehner</td>
      <td data-value="-3283200000" role="cell" class="epp-ar">1969-11-24</td>
      <td role="cell">Port Randyburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Kenneth</td>
      <td role="cell">Powlowski</td>
      <td data-value="-309312000000" role="cell" class="epp-ar">1960-03-14</td>
      <td role="cell">West Jaquelinetown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Jettie</td>
      <td role="cell">Rohan</td>
      <td data-value="365472000000" role="cell" class="epp-ar">1981-08-01</td>
      <td role="cell">Idellburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Bradley</td>
      <td role="cell">Fisher</td>
      <td data-value="-845942400000" role="cell" class="epp-ar">1943-03-13</td>
      <td role="cell">West Miguel</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Brook</td>
      <td role="cell">Kuhlman</td>
      <td data-value="-287280000000" role="cell" class="epp-ar">1960-11-24</td>
      <td role="cell">Lake Cleo</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Trystan</td>
      <td role="cell">Kerluke</td>
      <td data-value="844992000000" role="cell" class="epp-ar">1996-10-11</td>
      <td role="cell">North Alexa</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Layne</td>
      <td role="cell">Nicolas</td>
      <td data-value="1494288000000" role="cell" class="epp-ar">2017-05-09</td>
      <td role="cell">Port Loyberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Beaulah</td>
      <td role="cell">Berge</td>
      <td data-value="693878400000" role="cell" class="epp-ar">1991-12-28</td>
      <td role="cell">West Luella</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Estevan</td>
      <td role="cell">Auer</td>
      <td data-value="-1311811200000" role="cell" class="epp-ar">1928-06-07</td>
      <td role="cell">North Rodrick</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jensen</td>
      <td role="cell">Gutmann</td>
      <td data-value="1146873600000" role="cell" class="epp-ar">2006-05-06</td>
      <td role="cell">Marvinfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Frances</td>
      <td role="cell">Block</td>
      <td data-value="-456537600000" role="cell" class="epp-ar">1955-07-15</td>
      <td role="cell">West Winston</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Aurelie</td>
      <td role="cell">Koepp</td>
      <td data-value="421286400000" role="cell" class="epp-ar">1983-05-09</td>
      <td role="cell">Kozeyport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Maribel</td>
      <td role="cell">Johnston</td>
      <td data-value="655430400000" role="cell" class="epp-ar">1990-10-09</td>
      <td role="cell">Pearlborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Kaya</td>
      <td role="cell">Olson</td>
      <td data-value="404006400000" role="cell" class="epp-ar">1982-10-21</td>
      <td role="cell">South Janisbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Wilfrid</td>
      <td role="cell">Reynolds</td>
      <td data-value="717724800000" role="cell" class="epp-ar">1992-09-29</td>
      <td role="cell">North Salvatore</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Israel</td>
      <td role="cell">Paucek</td>
      <td data-value="257299200000" role="cell" class="epp-ar">1978-02-26</td>
      <td role="cell">Gillianfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jon</td>
      <td role="cell">Koss</td>
      <td data-value="1577923200000" role="cell" class="epp-ar">2020-01-02</td>
      <td role="cell">Lake Gwendolynberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Lacey</td>
      <td role="cell">Blick</td>
      <td data-value="956448000000" role="cell" class="epp-ar">2000-04-23</td>
      <td role="cell">Willview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Owen</td>
      <td role="cell">Denesik</td>
      <td data-value="-1169942400000" role="cell" class="epp-ar">1932-12-05</td>
      <td role="cell">Riceside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Kristoffer</td>
      <td role="cell">Mills</td>
      <td data-value="1054857600000" role="cell" class="epp-ar">2003-06-06</td>
      <td role="cell">North Kayleigh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Bethany</td>
      <td role="cell">Schinner</td>
      <td data-value="-506908800000" role="cell" class="epp-ar">1953-12-09</td>
      <td role="cell">South Garnetberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Nya</td>
      <td role="cell">Corkery</td>
      <td data-value="1498435200000" role="cell" class="epp-ar">2017-06-26</td>
      <td role="cell">South Pearl</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Emmanuel</td>
      <td role="cell">Senger</td>
      <td data-value="-10627200000" role="cell" class="epp-ar">1969-08-31</td>
      <td role="cell">Pietroberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Kole</td>
      <td role="cell">Corkery</td>
      <td data-value="-74304000000" role="cell" class="epp-ar">1967-08-25</td>
      <td role="cell">South Herman</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Cicero</td>
      <td role="cell">Kozey</td>
      <td data-value="-1839456000000" role="cell" class="epp-ar">1911-09-18</td>
      <td role="cell">Port Narcisotown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Alyson</td>
      <td role="cell">Mertz</td>
      <td data-value="-1478908800000" role="cell" class="epp-ar">1923-02-20</td>
      <td role="cell">Lake Isaistad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Christine</td>
      <td role="cell">Wiegand</td>
      <td data-value="1412899200000" role="cell" class="epp-ar">2014-10-10</td>
      <td role="cell">Flatleyville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Torey</td>
      <td role="cell">Harber</td>
      <td data-value="-1564963200000" role="cell" class="epp-ar">1920-05-30</td>
      <td role="cell">Oberbrunnertown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Javonte</td>
      <td role="cell">Morar</td>
      <td data-value="-785116800000" role="cell" class="epp-ar">1945-02-14</td>
      <td role="cell">Kuhicville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Blanca</td>
      <td role="cell">Ullrich</td>
      <td data-value="-159753600000" role="cell" class="epp-ar">1964-12-09</td>
      <td role="cell">North Triston</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Hans</td>
      <td role="cell">Maggio</td>
      <td data-value="-1341705600000" role="cell" class="epp-ar">1927-06-27</td>
      <td role="cell">West Chloehaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Samara</td>
      <td role="cell">Hoeger</td>
      <td data-value="-180403200000" role="cell" class="epp-ar">1964-04-14</td>
      <td role="cell">South Doyle</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Vada</td>
      <td role="cell">Pouros</td>
      <td data-value="-499996800000" role="cell" class="epp-ar">1954-02-27</td>
      <td role="cell">Jacobsonville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Mauricio</td>
      <td role="cell">Kihn</td>
      <td data-value="-2070316800000" role="cell" class="epp-ar">1904-05-25</td>
      <td role="cell">Treverfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Orval</td>
      <td role="cell">Pfannerstill</td>
      <td data-value="-1910563200000" role="cell" class="epp-ar">1909-06-17</td>
      <td role="cell">Macejkovicmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Aliya</td>
      <td role="cell">Littel</td>
      <td data-value="-1923955200000" role="cell" class="epp-ar">1909-01-13</td>
      <td role="cell">Jordimouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Everett</td>
      <td role="cell">Effertz</td>
      <td data-value="-1021766400000" role="cell" class="epp-ar">1937-08-16</td>
      <td role="cell">Consuelobury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Adrianna</td>
      <td role="cell">Hansen</td>
      <td data-value="384739200000" role="cell" class="epp-ar">1982-03-12</td>
      <td role="cell">New Tomasaview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">William</td>
      <td role="cell">Erdman</td>
      <td data-value="-379209600000" role="cell" class="epp-ar">1957-12-26</td>
      <td role="cell">Kerlukefurt</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;
}