This project has moved and is read-only. For the latest updates, please go here.

Object Reference Exception during saving package/ Writing out to a byte array.

Jan 12, 2012 at 1:48 PM

Hi All,

Thanks for the great package developed. I am using this excel package but unfortunately I get Object reference not set to an instance exception during saving the excel package/ Writing out the package to a byte array(I tried both).

My Code

             using (ExcelPackage epkg = new ExcelPackage(new FileInfo(rptTemplateName), true))
                ExcelWorkbook wbReport = epkg.Workbook;

                // Added Code as this is a fix for ExcelPackage module. Didn't Ckeck with EPPlus package though.
                foreach (ExcelWorksheet aworksheet in epkg.Workbook.Worksheets)
                    aworksheet.Cells[1, 1].Value = aworksheet.Cells[1, 1].Value;
                this.SendFileToClient("My Chart.xlsx", epkg.GetAsByteArray());


My 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 MyCode.FillReport(String rptCode) in d:\Dashboard.aspx.cs:line 739


Thanks & Regards

Arun Kumar Allu

Jan 16, 2012 at 10:59 AM
Edited Jan 16, 2012 at 11:01 AM

Any Ideas??

Jan 16, 2012 at 11:28 AM

After a lot of brainstorming and experimenting, I finally downloaded the source code, Rebuilt the solution and used the generated dll's in my project. Now the code is working.

It seems there is some issues with the binaries posted for download. Plz Check and do the needful.


Thanks & Regards

Arun Kumar Allu