question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

non-generated Pivot Table regression

See original GitHub issue

Do 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:

https://github.com/ClosedXML/ClosedXML/blob/69e37ad5f9d936c67d259e46582374930a23dd5f/ClosedXML/Excel/XLWorkbook_Load.cs#L714-L720

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:

https://github.com/ClosedXML/ClosedXML/blob/9cded9044050523f87567271d72b382505ec2c2e/ClosedXML/Excel/XLWorkbook_Load.cs#L913-L920

wss can be null with external sources so it needs to return early.

Issue Analytics

  • State:open
  • Created 2 months ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
rkleccommented, Aug 1, 2023

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.

If you click refresh all on pivot table, the exception might go away.

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.

I will look if I can add some simple check to ignore pivot fields that are missing from source workbook.

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?).

1reaction
jahavcommented, Jul 31, 2023

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.

  • I need an abstraction of pivot cache (IXLPivotCache). That was added in 0.102 .
  • I need to add shared string table, because pivot cache data references strings through SST. That was already merged to 0.103.
  • I need to load data to the the cache from workbook and save them back to the workbook. TBD.

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

analyzing data using pivot tables - YouTube
analyzing data using pivot tables. Mona Schraer. Mona Schraer. 1.45K subscribers. Subscribe. <__slot-el>. Subscribed.
Read more >
How to apply Linear regression on Pivot table (Any chart)
1 Answer 1 ... There is no built-in way to do this with PivotTable.js but you may pass additional information to the Renderers...
Read more >
Introductory Econometrics Chapter 3: Pivot Tables
Chapter 3: PivotTables. This chapter focuses on summarizing and describing patterns in data via tables. Tables efficiently convey basic summary information ...
Read more >
Pivot Table | PDF | Regression Analysis
Pivot Table - Free download as Powerpoint Presentation (.ppt), PDF File (.pdf), ... Simple linear regression, interpreting regression statistics;.
Read more >
Pivot Table
Creating a pivot table allows you to compare variables to each other in a heavily customizable, cross tab-like table. The cell values for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found