public static List<ExportItem> GetTestData () { var lst = new List<ExportItem>(); for (int i = 0; i < 100; i++) { lst.Add(new ExportItem() { column1 = ExportItem.RandomString(25), column2 = ExportItem.random.Next(1000, 9999), column3 = DateTime.Now.AddDays(ExportItem.random.Next(-100, +100)).AddHours(ExportItem.random.Next(-11, +11)).AddMinutes(ExportItem.random.Next(-59, +59)), column4 = (decimal)ExportItem.random.Next(10000, 99999) / 100, column5 = (decimal)ExportItem.random.Next(10000, 99999) / 100 }); } return lst; }
public void FirstTest() { using (ExcelPackage pck = new ExcelPackage()) { var ws_dades = pck.AddWorkSheet("DataSheet"); ws_dades.AddTable <ExportItem>("Table1", ExportItem.GetTestData(), ShowTotal: true); var ws_promotor = pck.AddWorkSheet("PivottableSheet"); ws_promotor.AddPivotTable <ExportItem>("PivotTable", ws_dades.Cells[ws_dades.Dimension.Address]); string path = @"C:\temp\test1.xlsx"; Stream stream = File.Create(path); pck.SaveAs(stream); stream.Close(); } }