Skip to content
This repository has been archived by the owner on Mar 9, 2020. It is now read-only.

"Object reference not set to an instance of an object." after removing Pivot table source #68

Closed
paaresh opened this issue Nov 23, 2017 · 3 comments

Comments

@paaresh
Copy link

paaresh commented Nov 23, 2017

Version : 4.5.0-beta
I am getting "Object reference not set to an instance of an object." in below case :

  1. Using EPPlus, Create new xlsx with Worksheet name "Sheet1" and data with table name "Table1" and save it
  2. Manually I added pivot table base on "Table1" using MS Office 2013
  3. Using EPPlus, Delete "Sheet1" and new worksheet with name "Sheet1" and add some data with table name "Table3" and call ExcelPackage.Save(). It will throw error.

It should allow to save excel file even though there is missing reference (Same like "ClosedXML").

System.InvalidOperationException: Error saving file G:\Export\exp_2.xlsx ---> System.NullReferenceException: Object reference not set to an instance of an object.
at OfficeOpenXml.ExcelWorksheet.SavePivotTables()
at OfficeOpenXml.ExcelWorksheet.Save()
at OfficeOpenXml.ExcelWorkbook.Save()
at OfficeOpenXml.ExcelPackage.Save()
--- End of inner exception stack trace ---
at OfficeOpenXml.ExcelPackage.Save()
at Query.CreateExcel(OleDbDataReader dr, String strFile) in G:\Export\Query.aspx.vb:line 4006
at Query.ExportData() in G:\Export\Queryaspx.vb:line 1644

@paaresh
Copy link
Author

paaresh commented Feb 22, 2018

has it been solved? or not entertaining the issue?

@giuliohome
Copy link

I have an xlsm file with this issue.
It has many sheets and many pivot tables: how can I programmatically check of a pivot table is not ok?
Thank you

@phillyDrew
Copy link

i spent a chunk of time wracking my brain over this.. in one script task i delete a template worksheet, referencing the spreadsheet by name. in another script task i get a null pointer exception when attempting to reference a different worksheet by name.

after literally scouring my statements for syntax or logic issue, i came to the deduction that there must be something else going on.

on a hunch... i commented out the delete portion, and then it ran ok... then uncommented it out and moved it after the one that was previously erroring.

it's gotta be something with how EPPLUS accesses and modifies the internal excel worksheet indexing, even though in my case the calls to open and individual variable assignments were by using string literals of named worksheets in completely different script tasks.

if i can advise, try not to delete anything until the very end, after all of the references are completed.

hope that helps anyone else

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants