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 Brionna Jenkins 1972-10-13 Zachariahtown
Wales Abdiel Daugherty 2005-10-24 Greenstad
England Antwan Moen 2020-09-19 East Bernhardstad
Scotland Justice Wolf 1949-11-06 Port Monserratland
Scotland Angus Abshire 1934-04-19 Lake Abigayle
Northern Ireland Shirley Gutkowski 1985-03-29 Sofiaburgh
England Mittie Labadie 1963-11-05 Belleburgh
Scotland Keeley Cruickshank 1992-09-21 North Vicenteburgh
Scotland Theodore Reinger 1977-10-22 Kathrynestad
Scotland Alanna Renner 1964-11-09 Priceborough
England Sandy Lowe 1982-06-05 Port Aidan
Wales Easter Stark 2018-09-19 West Cobyport
Scotland Kendall O'Hara 1949-02-28 Buckridgeshire
Northern Ireland Amiya Mayer 1964-11-08 Gertrudeshire
Wales Geovany Rosenbaum 2017-05-10 Okunevaville
Scotland Hildegard Pacocha 1964-05-28 North Darrion
Scotland Nelda Legros 1964-06-12 Ginoton
Wales Candida Jacobi 1959-12-30 Gaylordland
Scotland Veronica Spencer 1933-11-10 Port Aldenborough
Northern Ireland Ebba Donnelly 1997-03-03 East Andrewmouth
England Cesar Gislason 2005-08-22 East Willowton
Wales Edgardo Wisozk 1942-03-26 Sawaynview
Wales Hipolito Stracke 1967-07-04 Wittingport
England Charles Greenholt 2006-02-18 New Skylarberg
England Alverta Blick 1971-08-27 Bridiehaven
Northern Ireland Leslie Auer 1963-07-26 Lake Ford
Northern Ireland Yessenia Hudson 2012-04-10 Edmundside
Northern Ireland Alfreda Sawayn 1956-12-20 Willbury
England Danyka Towne 2003-10-07 Dockborough
Northern Ireland Webster Padberg 1964-07-04 Lake Emmyhaven
England Providenci Walter 1990-03-13 South Evalyn
Wales Carley Spencer 1978-03-27 West Alanafort
Northern Ireland Magali Morissette 1964-04-29 Port Grayson
Scotland Kellen Koelpin 1950-09-20 Port Anabelleburgh
Wales Misael Borer 1930-01-18 Ayanamouth
Wales Americo Gutkowski 2018-08-19 North Daniela
England Stanton Brakus 1964-09-05 Leilaniside
Northern Ireland Marjolaine Flatley 1955-12-21 West Eulahfurt
Scotland Nils Littel 2018-01-23 East Linwoodmouth
Scotland Kaylin Willms 1964-09-28 New Alaniston
Scotland Micaela Lebsack 1930-06-25 Deionshire
Northern Ireland Cornell Keeling 1947-12-21 Katelinfurt
Scotland Hildegard Witting 1964-02-11 Aurelieview
Wales Rowland Crona 1948-11-28 East Gregg
England Ava Kovacek 2014-01-17 Londonview
Scotland Sabrina O'Kon 1977-08-13 New Hollisport
Wales Rozella Sipes 1982-11-08 New Neal
Northern Ireland Newton Herman 1914-05-27 Francisborough
Wales Esmeralda Zboncak 1980-05-07 Willborough
Northern Ireland Kelly Langworth 1936-03-29 Rosalynmouth

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">Brionna</td>
      <td role="cell">Jenkins</td>
      <td data-value="87782400000" role="cell" class="epp-ar">1972-10-13</td>
      <td role="cell">Zachariahtown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Abdiel</td>
      <td role="cell">Daugherty</td>
      <td data-value="1130112000000" role="cell" class="epp-ar">2005-10-24</td>
      <td role="cell">Greenstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Antwan</td>
      <td role="cell">Moen</td>
      <td data-value="1600473600000" role="cell" class="epp-ar">2020-09-19</td>
      <td role="cell">East Bernhardstad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Justice</td>
      <td role="cell">Wolf</td>
      <td data-value="-635990400000" role="cell" class="epp-ar">1949-11-06</td>
      <td role="cell">Port Monserratland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Angus</td>
      <td role="cell">Abshire</td>
      <td data-value="-1126742400000" role="cell" class="epp-ar">1934-04-19</td>
      <td role="cell">Lake Abigayle</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Shirley</td>
      <td role="cell">Gutkowski</td>
      <td data-value="480902400000" role="cell" class="epp-ar">1985-03-29</td>
      <td role="cell">Sofiaburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Mittie</td>
      <td role="cell">Labadie</td>
      <td data-value="-194313600000" role="cell" class="epp-ar">1963-11-05</td>
      <td role="cell">Belleburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Keeley</td>
      <td role="cell">Cruickshank</td>
      <td data-value="717033600000" role="cell" class="epp-ar">1992-09-21</td>
      <td role="cell">North Vicenteburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Theodore</td>
      <td role="cell">Reinger</td>
      <td data-value="246326400000" role="cell" class="epp-ar">1977-10-22</td>
      <td role="cell">Kathrynestad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Alanna</td>
      <td role="cell">Renner</td>
      <td data-value="-162345600000" role="cell" class="epp-ar">1964-11-09</td>
      <td role="cell">Priceborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Sandy</td>
      <td role="cell">Lowe</td>
      <td data-value="392083200000" role="cell" class="epp-ar">1982-06-05</td>
      <td role="cell">Port Aidan</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Easter</td>
      <td role="cell">Stark</td>
      <td data-value="1537315200000" role="cell" class="epp-ar">2018-09-19</td>
      <td role="cell">West Cobyport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Kendall</td>
      <td role="cell">O'Hara</td>
      <td data-value="-657676800000" role="cell" class="epp-ar">1949-02-28</td>
      <td role="cell">Buckridgeshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Amiya</td>
      <td role="cell">Mayer</td>
      <td data-value="-162432000000" role="cell" class="epp-ar">1964-11-08</td>
      <td role="cell">Gertrudeshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Geovany</td>
      <td role="cell">Rosenbaum</td>
      <td data-value="1494374400000" role="cell" class="epp-ar">2017-05-10</td>
      <td role="cell">Okunevaville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Hildegard</td>
      <td role="cell">Pacocha</td>
      <td data-value="-176601600000" role="cell" class="epp-ar">1964-05-28</td>
      <td role="cell">North Darrion</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Nelda</td>
      <td role="cell">Legros</td>
      <td data-value="-175305600000" role="cell" class="epp-ar">1964-06-12</td>
      <td role="cell">Ginoton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Candida</td>
      <td role="cell">Jacobi</td>
      <td data-value="-315792000000" role="cell" class="epp-ar">1959-12-30</td>
      <td role="cell">Gaylordland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Veronica</td>
      <td role="cell">Spencer</td>
      <td data-value="-1140566400000" role="cell" class="epp-ar">1933-11-10</td>
      <td role="cell">Port Aldenborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Ebba</td>
      <td role="cell">Donnelly</td>
      <td data-value="857347200000" role="cell" class="epp-ar">1997-03-03</td>
      <td role="cell">East Andrewmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Cesar</td>
      <td role="cell">Gislason</td>
      <td data-value="1124668800000" role="cell" class="epp-ar">2005-08-22</td>
      <td role="cell">East Willowton</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Edgardo</td>
      <td role="cell">Wisozk</td>
      <td data-value="-876355200000" role="cell" class="epp-ar">1942-03-26</td>
      <td role="cell">Sawaynview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Hipolito</td>
      <td role="cell">Stracke</td>
      <td data-value="-78796800000" role="cell" class="epp-ar">1967-07-04</td>
      <td role="cell">Wittingport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Charles</td>
      <td role="cell">Greenholt</td>
      <td data-value="1140220800000" role="cell" class="epp-ar">2006-02-18</td>
      <td role="cell">New Skylarberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Alverta</td>
      <td role="cell">Blick</td>
      <td data-value="52099200000" role="cell" class="epp-ar">1971-08-27</td>
      <td role="cell">Bridiehaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Leslie</td>
      <td role="cell">Auer</td>
      <td data-value="-203126400000" role="cell" class="epp-ar">1963-07-26</td>
      <td role="cell">Lake Ford</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Yessenia</td>
      <td role="cell">Hudson</td>
      <td data-value="1334016000000" role="cell" class="epp-ar">2012-04-10</td>
      <td role="cell">Edmundside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Alfreda</td>
      <td role="cell">Sawayn</td>
      <td data-value="-411264000000" role="cell" class="epp-ar">1956-12-20</td>
      <td role="cell">Willbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Danyka</td>
      <td role="cell">Towne</td>
      <td data-value="1065484800000" role="cell" class="epp-ar">2003-10-07</td>
      <td role="cell">Dockborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Webster</td>
      <td role="cell">Padberg</td>
      <td data-value="-173404800000" role="cell" class="epp-ar">1964-07-04</td>
      <td role="cell">Lake Emmyhaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Providenci</td>
      <td role="cell">Walter</td>
      <td data-value="637286400000" role="cell" class="epp-ar">1990-03-13</td>
      <td role="cell">South Evalyn</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Carley</td>
      <td role="cell">Spencer</td>
      <td data-value="259804800000" role="cell" class="epp-ar">1978-03-27</td>
      <td role="cell">West Alanafort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Magali</td>
      <td role="cell">Morissette</td>
      <td data-value="-179107200000" role="cell" class="epp-ar">1964-04-29</td>
      <td role="cell">Port Grayson</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Kellen</td>
      <td role="cell">Koelpin</td>
      <td data-value="-608515200000" role="cell" class="epp-ar">1950-09-20</td>
      <td role="cell">Port Anabelleburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Misael</td>
      <td role="cell">Borer</td>
      <td data-value="-1260835200000" role="cell" class="epp-ar">1930-01-18</td>
      <td role="cell">Ayanamouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Americo</td>
      <td role="cell">Gutkowski</td>
      <td data-value="1534636800000" role="cell" class="epp-ar">2018-08-19</td>
      <td role="cell">North Daniela</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Stanton</td>
      <td role="cell">Brakus</td>
      <td data-value="-167961600000" role="cell" class="epp-ar">1964-09-05</td>
      <td role="cell">Leilaniside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Marjolaine</td>
      <td role="cell">Flatley</td>
      <td data-value="-442800000000" role="cell" class="epp-ar">1955-12-21</td>
      <td role="cell">West Eulahfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Nils</td>
      <td role="cell">Littel</td>
      <td data-value="1516665600000" role="cell" class="epp-ar">2018-01-23</td>
      <td role="cell">East Linwoodmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Kaylin</td>
      <td role="cell">Willms</td>
      <td data-value="-165974400000" role="cell" class="epp-ar">1964-09-28</td>
      <td role="cell">New Alaniston</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Micaela</td>
      <td role="cell">Lebsack</td>
      <td data-value="-1247184000000" role="cell" class="epp-ar">1930-06-25</td>
      <td role="cell">Deionshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Cornell</td>
      <td role="cell">Keeling</td>
      <td data-value="-695260800000" role="cell" class="epp-ar">1947-12-21</td>
      <td role="cell">Katelinfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Hildegard</td>
      <td role="cell">Witting</td>
      <td data-value="-185846400000" role="cell" class="epp-ar">1964-02-11</td>
      <td role="cell">Aurelieview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Rowland</td>
      <td role="cell">Crona</td>
      <td data-value="-665625600000" role="cell" class="epp-ar">1948-11-28</td>
      <td role="cell">East Gregg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Ava</td>
      <td role="cell">Kovacek</td>
      <td data-value="1389916800000" role="cell" class="epp-ar">2014-01-17</td>
      <td role="cell">Londonview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Sabrina</td>
      <td role="cell">O'Kon</td>
      <td data-value="240278400000" role="cell" class="epp-ar">1977-08-13</td>
      <td role="cell">New Hollisport</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Rozella</td>
      <td role="cell">Sipes</td>
      <td data-value="405561600000" role="cell" class="epp-ar">1982-11-08</td>
      <td role="cell">New Neal</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Newton</td>
      <td role="cell">Herman</td>
      <td data-value="-1754611200000" role="cell" class="epp-ar">1914-05-27</td>
      <td role="cell">Francisborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Esmeralda</td>
      <td role="cell">Zboncak</td>
      <td data-value="326505600000" role="cell" class="epp-ar">1980-05-07</td>
      <td role="cell">Willborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Kelly</td>
      <td role="cell">Langworth</td>
      <td data-value="-1065398400000" role="cell" class="epp-ar">1936-03-29</td>
      <td role="cell">Rosalynmouth</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;
}