Skip to content
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

DataConsolidateFunction mapping to wrong ST_DataConsolidateFunction #697

Closed
davidthemaster30 opened this issue Nov 22, 2021 · 5 comments
Closed
Assignees
Labels
Milestone

Comments

@davidthemaster30
Copy link

When using pivotTable.AddColumnLabel(DataConsolidateFunction.COUNT, 5) the expected result should be a pivottable with a new datafield with a subtotal of "count", however it is mapped to "countNums".

The reason being ST_DataConsolidateFunction is an enum with values starting at 0 and DataConsolidateFunction are static classes starting with 1.

Here is where the conversion occurs:

dataField.subtotal = (ST_DataConsolidateFunction)(function.Value);

DataConsolidateFunction.COUNT.Value = 2
(ST_DataConsolidateFunction)(1) = count
(ST_DataConsolidateFunction)(2) = countNums

Possible solutions:

  1. start enum ST_DataConsolidateFunction mapping at 1
    public enum ST_DataConsolidateFunction{ average = 1, count = 2, countNums = 3, //etc }
  2. Change dataField.subtotal = (ST_DataConsolidateFunction)(function.Value); to dataField.subtotal = (ST_DataConsolidateFunction)(function.Value-1);

Current workaround is to force the correct ST_DataConsolidateFunction after using pivotTable.AddColumnLabel(DataConsolidateFunction.COUNT, 5):
definitions.dataFields.dataField[0].subtotal = ST_DataConsolidateFunction.count;

@tonyqus tonyqus added the bug label Nov 22, 2021
@tonyqus tonyqus added this to the NPOI 2.5.6 milestone Nov 22, 2021
@tonyqus
Copy link
Member

tonyqus commented Dec 14, 2021

This is the original code in Java.
dataField.setSubtotal(STDataConsolidateFunction.Enum.forInt(function.getValue()));

Looks POI also has the same problem.

@tonyqus
Copy link
Member

tonyqus commented Dec 14, 2021

Do you have an Excel file that I can use to reproduce this issue?

@davidthemaster30
Copy link
Author

I do not, because I've never gotten a working pivotTable that didn't crash Excel.

@tonyqus
Copy link
Member

tonyqus commented Feb 6, 2022

I accept your second solution:
dataField.subtotal = (ST_DataConsolidateFunction)(function.Value-1);

The pivot table in NPOI still needs a few test to make it work. Thank you for your issue. This can definitely help NPOI.

@tonyqus
Copy link
Member

tonyqus commented Feb 6, 2022

I finally change the values of DataConsolidateFunction in order to align with enum values of ST_DataConsolidateFunction.

public static DataConsolidateFunction AVERAGE = new DataConsolidateFunction(0, "Average"),

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

No branches or pull requests

2 participants