non-generated Pivot Table regression
See original GitHub issueDo you want to request a feature or report a bug?
- Bug
- Feature
- Question
Did you test against the latest CI build?
- Yes
- No
If you answered No
, please test with the latest development build first.
I cloned and ran locally via ClosedXML.Sandbox.
Version of ClosedXML
0.102.0
What is the current behavior?
Exception during load of a vendor provided spreadsheet.
System.ArgumentOutOfRangeException: The column 'xyz' does not appear in the source range. (Parameter 'sourceName')
at ClosedXML.Excel.XLPivotFields.Add(String sourceName, String customName)
at ClosedXML.Excel.XLPivotFields.Add(String sourceName)
at ClosedXML.Excel.XLWorkbook.LoadSpreadsheetDocument(SpreadsheetDocument dSpreadsheet)
at ClosedXML.Excel.XLWorkbook.LoadSheets(Stream stream)
at ClosedXML.Excel.XLWorkbook.Load(Stream stream)
at ClosedXML.Excel.XLWorkbook..ctor(Stream stream, LoadOptions loadOptions)
at ClosedXML.Excel.XLWorkbook..ctor(Stream stream)
...
What is the expected behavior or new feature?
Spreadsheet is loaded.
Is this a regression from the previous version?
Yes. Works in 0.101.0
Reproducibility
Code to reproduce problem: The exception happens during the load of an existing file with a lot of pivot tables and connections. I’m sorry but a code sample isnt really helpful here.
new XLWorkbook("file")
- I attached a sample spreadsheet. (You can drag files on to this issue)
I dont have enough Excel experience to recreate this issue myself and I cant attach the file from the vendor.
I did spend a bit troubleshooting in the code and noticed a couple things.
At the previous commit, there was a check that the field is available before trying to add it in several places:
I assume this is what avoided the exception that is currently being thrown in XLPivotFields.Add
.
When i skipped the bad adds in troubleshooting, I also ran into an exception where wss is null in ParsePivotSourceReference:
wss
can be null with external sources so it needs to return early.
Issue Analytics
- State:
- Created 2 months ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top GitHub Comments
Thanks. That reproducer Excel file works and I can reproduce the issue with that Excel with v0.102.0, but not 0.101. As such downgrading is a feasable workaround.
Yeah and that did not (fully) work for them. The thing is somehow the pivot table in my XLSX file has somehow been deleted completely, while the cache remains (and in the XSLX/ZIP file I can see) and yes, I don’t know how that could have happen, as I did not create that Excel file.
IMHO that would be great. Or a simple LoadOption to ignore all pivot fields/stuff maybe, because one may not actually need it and disabling it could be the simplest solution (for now?).
Repro workbook
ColumnDeletedFromWorksheetButNotFromPivotTable.xlsx
The root of the issue is that the source data in the workbook are stale. Pivot tables have their own copy of data they use to calculate and display pivot table (docs).
The problem is that ClosedXML doesn’t keep this data and just uses the original data from worksheet. If you delete a column from the worksheet, data are gone even from pivot table. Basically, the current state is fundamentally built on sand and needs to be fixed.
If you click refresh all on pivot table, the exception might go away. I will look if I can add some simple check to ignore pivot fields that are missing from source workbook.