This project has moved. For the latest updates, please go here.

Need help, I'm struggling with pivot creation

Feb 26, 2015 at 2:11 PM

I'm new to EPPlus and already managed to create simple Excel tables.

But now I'm struggling with creating a pivot table and need help.

I'm importing data from a csv file into a table like this:
while (csv.ReadNextRecord())
    ws.Cells[zeile,1].Value = csv[dheaders["Modul - Dokumentname"]];
    ws.Cells[zeile,3].Value = csv[dheaders["Leistungsart - Leistungsartenname"]];
    ws.Cells[zeile,5].Value = float.Parse(csv[dheaders["Anzahl"]]);
    ws.Cells[zeile,7].Value = float.Parse(csv[dheaders["Verkaufspreis"]]);
    ws.Cells[zeile,7].StyleName = "EuroAmount";
    ws.Cells[zeile,8].Formula = string.Format("{0}*{1}", new ExcelAddress(zeile,5,zeile,5), new ExcelAddress(zeile,7,zeile,7));
    ws.Cells[zeile,8].StyleName = "EuroAmount";                     
Then I create the pivot like this:
var dataRange = ws.Cells[ExcelRange.GetAddress(5,1,line,8)];

var pivotTable1 = wsPivot.PivotTables.Add(wsPivot.Cells["A1"], dataRange, "PerWorkstream");
But this causes Excel (2013) to crash when I open the excel file.

When I omit the last line the file can be opened, but the pivot does not show any

I would also like to know how to make the the datarange "named", so that the pivot can be properly updated when someone adds rows to the table in Excel.