-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Comments
This is the original code in Java. Looks POI also has the same problem. |
Do you have an Excel file that I can use to reproduce this issue? |
I do not, because I've never gotten a working pivotTable that didn't crash Excel. |
I accept your second solution: The pivot table in NPOI still needs a few test to make it work. Thank you for your issue. This can definitely help NPOI. |
I finally change the values of DataConsolidateFunction in order to align with enum values of ST_DataConsolidateFunction.
|
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:
npoi/ooxml/XSSF/UserModel/XSSFPivotTable.cs
Line 367 in c71d44c
DataConsolidateFunction.COUNT.Value = 2
(ST_DataConsolidateFunction)(1) = count
(ST_DataConsolidateFunction)(2) = countNums
Possible solutions:
public enum ST_DataConsolidateFunction{ average = 1, count = 2, countNums = 3, //etc }
dataField.subtotal = (ST_DataConsolidateFunction)(function.Value);
todataField.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;
The text was updated successfully, but these errors were encountered: