Pivot Table basic problem

Dec 19, 2011 at 2:13 PM

Hi, thanx for the nice project!

I am faced with the following problem and I can't figure out why....

I have a simple xlsx template file with a worksheet containing tabular data and a named range assigned to that table area. Using the library it all works fine, I can Load the file, Load the data and save it. I then open the file and its all there... nice and easy... 

However, the problem is that when i add a PivotTable on a new sheet and define its datasource by specifying that named range the file creation fails... I get a Null Reference Exception when i do pck.GetAsByteArray();

Stack Trace: at OfficeOpenXml.Table.PivotTable.ExcelPivotCacheDefinition..ctor(XmlNamespaceManager ns, ExcelPivotTable pivotTable)   at OfficeOpenXml.Table.PivotTable.ExcelPivotTable..ctor(PackageRelationship rel, ExcelWorksheet sheet)   at OfficeOpenXml.Table.PivotTable.ExcelPivotTableCollection..ctor(ExcelWorksheet ws)   at OfficeOpenXml.ExcelWorksheet.get_PivotTables()   at OfficeOpenXml.ExcelWorksheet.SavePivotTables()   at OfficeOpenXml.ExcelWorksheet.Save()   at OfficeOpenXml.ExcelWorkbook.Save()   at OfficeOpenXml.ExcelPackage.GetAsByteArray(Boolean save)   at OfficeOpenXml.ExcelPackage.GetAsByteArray()   at MyProject.Excel.EPPlusExcelExport.Export(ReportDefinition pReportDefintion, DataTable pSchemaTable, DataTable pData, String pTemplateName, String pExportFilePath, String pReportCustomizationPath,) in C:\xxx\xxx\xxx\xxx\EPPlusExcelExport.cs:line 195


I add the pivot table to the excel template using Excel 2010 itself, I don't add it programmatically. I do nothing to the Pivot Table in the code as I expect excel to do the rest when the file opens...

The other thing to mention is that if I remove the Pivot Table from the xlsx template and then use the library to create the document and then after the document opens up I add the pivot table setting its datasource to be that named range it all works fine...

So what's going on? Any ideas?

Thank you for any help, much appreciated!

Dec 19, 2011 at 2:56 PM

Hi, you can consider this issue as solved! The whole thing worked as soon as I used the source code in my project instead of the dll! The dll I was using was version while the source code is version the 85963 changeset.