EPPLus: Format as Table

Format data just like the "Format as Table" function in Excel.
using (var xlPackage = new ExcelPackage())
{
    // add a sheet
    var ws = xlPackage.Workbook.Worksheets.Add("Sheet1");

    // add data to sheet
    // ws.SetValue(row, col, value);
    // ...

    // select the range that will be included in the table
    var range = ws.Cells[startRow, startColumn, endRow, endColumn];

    // add the excel table entity
    var table = ws.Tables.Add(range, "table1");
    table.ShowTotal = true;
    table.TableStyle = TableStyles.Light2;

    // add aggregate formulas (get these from an existing table in Excel)
    table.Columns[1].TotalsRowFormula = "SUBTOTAL(103,[Column1])"; // count
    table.Columns[2].TotalsRowFormula = "SUBTOTAL(109,[Column2])"; // sum
    table.Columns[3].TotalsRowFormula = "SUBTOTAL(101,[Column3])"; // average
    
    return xlPackage.GetAsByteArray();
}

IIS 7: Windows Authentication Not Listed

  1. Open Server Manager (Right Click Computer, Click Manage)
  2. Expand Roles, Right Click Web Server, Click Add Role
  3. Expand Web Server -> Security, Check Windows Authentication
  4. Click Install