-
Notifications
You must be signed in to change notification settings - Fork 840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pivot table - support groups fields #2130
Comments
May be related/same as #783, also having that error with spurious Re-creating or running these macros or so to refresh the pivot cache kinda works and "just" makes the error return a new (non-existent) column/ArgumentOutOfRangeException. |
I can confirm this error does not happen with v0.101.0 and is a regression/new in v0.102.0. |
Repro workbook using var wb = new XLWorkbook(@"c:\Temp\Issues\2130\ColumnDeletedFromWorksheetButNotFromPivotTable.xlsx"); 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. |
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?). |
Note I have reproduced this again with my customer-provided Excel file (which I described above) and even in ClosedXML v0.100.3 up to the current stable one, it does fail with the same error. That is interesting, because your ColumnDeletedFromWorksheetButNotFromPivotTable.xlsx is indeed different here and works with v0.101.0 as said. |
Resolved through #2178, #2182, #2183 and #2186. The original post didn't contain a test file, but pivot cache now loads records and uses pivot cache instead of data from workbook directly. That is loading only. Pivot table saving code doesn't work properly for pivot tables with deleted source (or some related reason). Saved files (example) without a valid reference to source data will have a empty pivot table (also shows an error on load because But it doesn't crash on load that is the sound of progress 🥇 |
Unfortunately it's still failing to load my vendor provided spreadsheet. It's a mess inside, believe me. I don't need any of the data from the pivot tables, so I'm sorry that I'm adding additional work to handle my edge-case. Should I open a new issue since this continues to not work for this file? And since I'm running into two different issues, let me know if I should open another issue to split them.
This one I think I know how to pretty easily fix. I pointed out in the original description how
The presence of the databaseField attribute seems to be the only difference with this field compared to others. This would be fixable by having Edit: I tried out continuing based on the presence of DatabaseField and it was a big mistake. It's needed later to load the column names and data. A different approach is needed 😄 |
@jahav sorry to ping you, but I assume you didnt get a prior notification |
The pivot table is using group fields. ClosedXML has a long way before that is supported. As far as databaseFields: MS-OI29500 (that is basically a patch over ISO29500 how does Excel actually implement the OOXML and fixes a lot of bugs in the standard) says
|
Would it make sense in the current implementation to add a |
No. It makes no sense to work with advanced features when I don't even have proper representation of basic features. |
@jahav hello again! I would love to be able to make use of the performance improvements and enhancements you've been working on. Would you be opposed to skipping over any DatabaseFields inside This resolves one of the issues with my input file. The other issue is with an external CacheSource so the WorksheetSource is null. I can create 2 PR's if you are amenable to the changes above. Thanks! |
Do you want to request a feature or report a bug?
Did you test against the latest CI build?
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.
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.
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:
ClosedXML/ClosedXML/Excel/XLWorkbook_Load.cs
Lines 714 to 720 in 69e37ad
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:
ClosedXML/ClosedXML/Excel/XLWorkbook_Load.cs
Lines 913 to 920 in 9cded90
wss
can be null with external sources so it needs to return early.The text was updated successfully, but these errors were encountered: