Created
January 25, 2013 16:19
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Painless way to build Microsoft Excel spreadsheets from any IEnumerable. Does not require Excel.