Skip to content

Instantly share code, notes, and snippets.

@bryanhunter
Created January 25, 2013 16:19
Show Gist options
  • Save bryanhunter/4635707 to your computer and use it in GitHub Desktop.
Save bryanhunter/4635707 to your computer and use it in GitHub Desktop.
Painless way to build Microsoft Excel spreadsheets from any IEnumerable<T>. Does not require Excel.
using System.Collections.Generic;
using System.IO;
using OfficeOpenXml; // (EPPLus - http://epplus.codeplex.com/)
namespace OfficeReports
{
public static class DumpToExcel
{
public static void Dump<T>(IEnumerable<T> data, string outputFilename)
{
var fileInfo = new FileInfo(outputFilename);
using (var package = new ExcelPackage(fileInfo))
{
var worksheet = package.Workbook.Worksheets.Add("Report");
worksheet.Cells["A1"].LoadFromCollection(data, true);
package.Save();
}
}
}
}
@tarasn
Copy link

tarasn commented Jun 26, 2013

Painless way to build Microsoft Excel spreadsheets from any IEnumerable. Does not require Excel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment