Generic Excel Generator function for EPPlus

asp.net-mvc, c#, epplus, linq

Solution

There is now a more simple way to achieve this using the LoadFromCollection method.

public void ExportToExcel(IEnumerable<Employee> employees, FileInfo targetFile)
{
    using (var excelFile = new ExcelPackage(targetFile))
    {
        var worksheet = excelFile.Workbook.Worksheets.Add("Sheet1");
        worksheet.Cells["A1"].LoadFromCollection(Collection: employees, PrintHeaders: true);
        excelFile.Save();
    }
}

Example taken from here: http://gruffcode.com/2013/10/30/simple-excel-export-with-epplus/

Problem

How would one build a generic EPPlus Spreadsheet function for your LINQ Queries? UPDATE: The need was specifically for an ASP.NET MVC application.

Original source