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 Kailee Renner 1938-04-01 East Jacquelynview
Northern Ireland Jerrell Rippin 2015-08-09 Oranborough
England Jannie Reynolds 1986-12-17 South Rupertfort
Wales Chase Feest 1919-06-02 Kubmouth
Wales Zackery Rempel 1927-07-11 East Deshawn
Scotland Lavinia Romaguera 2009-08-07 Krystinaside
Northern Ireland Filomena Murphy 2019-02-11 Goyettestad
Northern Ireland Laurianne Spinka 2026-06-04 Oramouth
England Brandi Deckow 1962-12-08 Port Dixie
Wales Karli Runte 1980-12-04 Champlintown
England Philip Pollich 1965-05-24 Lilianeshire
Scotland Layne Macejkovic 1940-05-25 Maiahaven
England Eulalia Hills 1909-02-27 West Nils
Wales Elbert Osinski 1938-12-09 North Casimer
Northern Ireland Jedidiah D'Amore 1996-08-19 East Gino
Scotland Cindy Gorczany 1988-11-23 Beierburgh
Wales Miller Buckridge 1985-07-26 Gracielatown
England Daniela Rodriguez 1922-10-08 Caesarmouth
Northern Ireland Trycia Raynor 2016-03-25 Elianfort
Scotland Aurelie Torphy 1962-12-16 Reedborough
Northern Ireland Lonny Wiegand 1967-03-23 South Anibalborough
Scotland Callie O'Hara 2020-10-05 Lynchshire
Wales Narciso Weimann 1973-03-20 East Elinorville
Northern Ireland Lindsey Kutch 1995-08-22 Port Miracle
Wales Jacquelyn Mayer 1965-09-09 Hermanfurt
Wales Jovani Koepp 1965-10-30 Queenieland
England Sheridan Muller 1941-04-16 Eliseostad
Northern Ireland Ruben Volkman 2019-03-15 Dinoborough
Scotland Katrine Haley 2022-02-18 Weissnatbury
Scotland Isom Goyette 2006-08-12 Quinnborough
Wales Whitney Lockman 1979-07-09 South Cornellbury
Scotland Pearlie Emmerich 1992-08-22 Kathleenside
England Maeve Littel 1933-10-23 West Amariberg
Scotland Marcos Krajcik 1982-09-08 Greenfelderland
England Vernice Erdman 2020-02-05 Lake Orvilletown
Scotland Timmy Hartmann 1983-01-09 Lake Cierra
England Donald Howe 2013-07-15 New Kayliview
Scotland Anabelle Osinski 1945-05-09 East Tomasa
Wales Ubaldo Hamill 1965-07-08 Haleyfort
England Julie Bode 1921-01-18 West Presleymouth
Scotland Domenick Kshlerin 1924-05-24 Lake Napoleonfort
Scotland Hank Berge 1991-05-12 Abbottberg
Wales Cody Fisher 1919-12-06 South Timmy
Northern Ireland Zachary Lesch 1994-03-03 Blandaville
Scotland Enoch Denesik 1970-08-14 Zulaufside
Scotland Moshe Little 1932-12-23 Whiteville
Wales Reagan Konopelski 1977-06-30 Vandervortmouth
Wales Isaiah Hamill 2001-11-08 Aubreebury
England Tevin Conn 1968-12-12 South Audra
Wales Shakira Gulgowski 1984-07-23 East Jacinthe

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">Kailee</td>
      <td role="cell">Renner</td>
      <td data-value="-1002067200000" role="cell" class="epp-ar epp-s1">1938-04-01</td>
      <td role="cell">East Jacquelynview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jerrell</td>
      <td role="cell">Rippin</td>
      <td data-value="1439078400000" role="cell" class="epp-ar epp-s1">2015-08-09</td>
      <td role="cell">Oranborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Jannie</td>
      <td role="cell">Reynolds</td>
      <td data-value="535161600000" role="cell" class="epp-ar epp-s1">1986-12-17</td>
      <td role="cell">South Rupertfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Chase</td>
      <td role="cell">Feest</td>
      <td data-value="-1596326400000" role="cell" class="epp-ar epp-s1">1919-06-02</td>
      <td role="cell">Kubmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Zackery</td>
      <td role="cell">Rempel</td>
      <td data-value="-1340496000000" role="cell" class="epp-ar epp-s1">1927-07-11</td>
      <td role="cell">East Deshawn</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Lavinia</td>
      <td role="cell">Romaguera</td>
      <td data-value="1249603200000" role="cell" class="epp-ar epp-s1">2009-08-07</td>
      <td role="cell">Krystinaside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Filomena</td>
      <td role="cell">Murphy</td>
      <td data-value="1549843200000" role="cell" class="epp-ar epp-s1">2019-02-11</td>
      <td role="cell">Goyettestad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Laurianne</td>
      <td role="cell">Spinka</td>
      <td data-value="1780531200000" role="cell" class="epp-ar epp-s1">2026-06-04</td>
      <td role="cell">Oramouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Brandi</td>
      <td role="cell">Deckow</td>
      <td data-value="-222998400000" role="cell" class="epp-ar epp-s1">1962-12-08</td>
      <td role="cell">Port Dixie</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Karli</td>
      <td role="cell">Runte</td>
      <td data-value="344736000000" role="cell" class="epp-ar epp-s1">1980-12-04</td>
      <td role="cell">Champlintown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Philip</td>
      <td role="cell">Pollich</td>
      <td data-value="-145411200000" role="cell" class="epp-ar epp-s1">1965-05-24</td>
      <td role="cell">Lilianeshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Layne</td>
      <td role="cell">Macejkovic</td>
      <td data-value="-934243200000" role="cell" class="epp-ar epp-s1">1940-05-25</td>
      <td role="cell">Maiahaven</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Eulalia</td>
      <td role="cell">Hills</td>
      <td data-value="-1920067200000" role="cell" class="epp-ar epp-s1">1909-02-27</td>
      <td role="cell">West Nils</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Elbert</td>
      <td role="cell">Osinski</td>
      <td data-value="-980294400000" role="cell" class="epp-ar epp-s1">1938-12-09</td>
      <td role="cell">North Casimer</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Jedidiah</td>
      <td role="cell">D'Amore</td>
      <td data-value="840412800000" role="cell" class="epp-ar epp-s1">1996-08-19</td>
      <td role="cell">East Gino</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Cindy</td>
      <td role="cell">Gorczany</td>
      <td data-value="596246400000" role="cell" class="epp-ar epp-s1">1988-11-23</td>
      <td role="cell">Beierburgh</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Miller</td>
      <td role="cell">Buckridge</td>
      <td data-value="491184000000" role="cell" class="epp-ar epp-s1">1985-07-26</td>
      <td role="cell">Gracielatown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Daniela</td>
      <td role="cell">Rodriguez</td>
      <td data-value="-1490572800000" role="cell" class="epp-ar epp-s1">1922-10-08</td>
      <td role="cell">Caesarmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Trycia</td>
      <td role="cell">Raynor</td>
      <td data-value="1458864000000" role="cell" class="epp-ar epp-s1">2016-03-25</td>
      <td role="cell">Elianfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Aurelie</td>
      <td role="cell">Torphy</td>
      <td data-value="-222307200000" role="cell" class="epp-ar epp-s1">1962-12-16</td>
      <td role="cell">Reedborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Lonny</td>
      <td role="cell">Wiegand</td>
      <td data-value="-87696000000" role="cell" class="epp-ar epp-s1">1967-03-23</td>
      <td role="cell">South Anibalborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Callie</td>
      <td role="cell">O'Hara</td>
      <td data-value="1601856000000" role="cell" class="epp-ar epp-s1">2020-10-05</td>
      <td role="cell">Lynchshire</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Narciso</td>
      <td role="cell">Weimann</td>
      <td data-value="101433600000" role="cell" class="epp-ar epp-s1">1973-03-20</td>
      <td role="cell">East Elinorville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Lindsey</td>
      <td role="cell">Kutch</td>
      <td data-value="809049600000" role="cell" class="epp-ar epp-s1">1995-08-22</td>
      <td role="cell">Port Miracle</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Jacquelyn</td>
      <td role="cell">Mayer</td>
      <td data-value="-136080000000" role="cell" class="epp-ar epp-s1">1965-09-09</td>
      <td role="cell">Hermanfurt</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Jovani</td>
      <td role="cell">Koepp</td>
      <td data-value="-131673600000" role="cell" class="epp-ar epp-s1">1965-10-30</td>
      <td role="cell">Queenieland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Sheridan</td>
      <td role="cell">Muller</td>
      <td data-value="-906076800000" role="cell" class="epp-ar epp-s1">1941-04-16</td>
      <td role="cell">Eliseostad</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Ruben</td>
      <td role="cell">Volkman</td>
      <td data-value="1552608000000" role="cell" class="epp-ar epp-s1">2019-03-15</td>
      <td role="cell">Dinoborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Katrine</td>
      <td role="cell">Haley</td>
      <td data-value="1645142400000" role="cell" class="epp-ar epp-s1">2022-02-18</td>
      <td role="cell">Weissnatbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Isom</td>
      <td role="cell">Goyette</td>
      <td data-value="1155340800000" role="cell" class="epp-ar epp-s1">2006-08-12</td>
      <td role="cell">Quinnborough</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Whitney</td>
      <td role="cell">Lockman</td>
      <td data-value="300326400000" role="cell" class="epp-ar epp-s1">1979-07-09</td>
      <td role="cell">South Cornellbury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Pearlie</td>
      <td role="cell">Emmerich</td>
      <td data-value="714441600000" role="cell" class="epp-ar epp-s1">1992-08-22</td>
      <td role="cell">Kathleenside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Maeve</td>
      <td role="cell">Littel</td>
      <td data-value="-1142121600000" role="cell" class="epp-ar epp-s1">1933-10-23</td>
      <td role="cell">West Amariberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Marcos</td>
      <td role="cell">Krajcik</td>
      <td data-value="400291200000" role="cell" class="epp-ar epp-s1">1982-09-08</td>
      <td role="cell">Greenfelderland</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Vernice</td>
      <td role="cell">Erdman</td>
      <td data-value="1580860800000" role="cell" class="epp-ar epp-s1">2020-02-05</td>
      <td role="cell">Lake Orvilletown</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Timmy</td>
      <td role="cell">Hartmann</td>
      <td data-value="410918400000" role="cell" class="epp-ar epp-s1">1983-01-09</td>
      <td role="cell">Lake Cierra</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Donald</td>
      <td role="cell">Howe</td>
      <td data-value="1373846400000" role="cell" class="epp-ar epp-s1">2013-07-15</td>
      <td role="cell">New Kayliview</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Anabelle</td>
      <td role="cell">Osinski</td>
      <td data-value="-777859200000" role="cell" class="epp-ar epp-s1">1945-05-09</td>
      <td role="cell">East Tomasa</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Ubaldo</td>
      <td role="cell">Hamill</td>
      <td data-value="-141523200000" role="cell" class="epp-ar epp-s1">1965-07-08</td>
      <td role="cell">Haleyfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Julie</td>
      <td role="cell">Bode</td>
      <td data-value="-1544832000000" role="cell" class="epp-ar epp-s1">1921-01-18</td>
      <td role="cell">West Presleymouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Domenick</td>
      <td role="cell">Kshlerin</td>
      <td data-value="-1439251200000" role="cell" class="epp-ar epp-s1">1924-05-24</td>
      <td role="cell">Lake Napoleonfort</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Hank</td>
      <td role="cell">Berge</td>
      <td data-value="674006400000" role="cell" class="epp-ar epp-s1">1991-05-12</td>
      <td role="cell">Abbottberg</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Cody</td>
      <td role="cell">Fisher</td>
      <td data-value="-1580169600000" role="cell" class="epp-ar epp-s1">1919-12-06</td>
      <td role="cell">South Timmy</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Northern Ireland</td>
      <td role="cell">Zachary</td>
      <td role="cell">Lesch</td>
      <td data-value="762652800000" role="cell" class="epp-ar epp-s1">1994-03-03</td>
      <td role="cell">Blandaville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Enoch</td>
      <td role="cell">Denesik</td>
      <td data-value="19440000000" role="cell" class="epp-ar epp-s1">1970-08-14</td>
      <td role="cell">Zulaufside</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Scotland</td>
      <td role="cell">Moshe</td>
      <td role="cell">Little</td>
      <td data-value="-1168387200000" role="cell" class="epp-ar epp-s1">1932-12-23</td>
      <td role="cell">Whiteville</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Reagan</td>
      <td role="cell">Konopelski</td>
      <td data-value="236476800000" role="cell" class="epp-ar epp-s1">1977-06-30</td>
      <td role="cell">Vandervortmouth</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Isaiah</td>
      <td role="cell">Hamill</td>
      <td data-value="1005177600000" role="cell" class="epp-ar epp-s1">2001-11-08</td>
      <td role="cell">Aubreebury</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">England</td>
      <td role="cell">Tevin</td>
      <td role="cell">Conn</td>
      <td data-value="-33264000000" role="cell" class="epp-ar epp-s1">1968-12-12</td>
      <td role="cell">South Audra</td>
    </tr>
    <tr role="row" scope="row">
      <td role="cell">Wales</td>
      <td role="cell">Shakira</td>
      <td role="cell">Gulgowski</td>
      <td data-value="459388800000" role="cell" class="epp-ar epp-s1">1984-07-23</td>
      <td role="cell">East Jacinthe</td>
    </tr>
  </tbody>
</table>
            
        

EPPlus converts the table styling in Excel to a separate stylesheet.

        
 table.epplus-table{
  font-family:Aptos Narrow;
  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;
}
.epp-s1{
  white-space: nowrap;
  vertical-align:bottom;
}