Bug 67271 - org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotField.setDefaultSubtotal(boolean arg) is not working
Summary: org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotField.setDefaultSu...
Status: RESOLVED INFORMATIONPROVIDED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 5.2.3-FINAL
Hardware: All Linux
: P2 blocker (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-09-07 06:09 UTC by Komal Anil Ghare
Modified: 2023-09-12 04:41 UTC (History)
1 user (show)



Attachments
Zip containing error messages, java code and error log file. (81.38 KB, application/x-zip-compressed)
2023-09-07 06:09 UTC, Komal Anil Ghare
Details
Zip containing input file and output file. (26.67 KB, application/x-zip-compressed)
2023-09-11 06:24 UTC, Komal Anil Ghare
Details
Updated the example code to initialize the pivot field items and the pivot cache definition (6.35 KB, text/plain)
2023-09-11 09:50 UTC, Matthias Raschhofer
Details
Remove subtotal rows for all pivot fields. (6.34 KB, text/plain)
2023-09-11 15:54 UTC, Matthias Raschhofer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Komal Anil Ghare 2023-09-07 06:09:23 UTC
Created attachment 38981 [details]
Zip containing error messages, java code and error log file.

We are creating pivot table with attached code(Please refer PivotTableCode.java). As a result intermediate subtotal is not getting disabled and file gets corrupted with attached error messages (Please refer Error1.jpg and Error2.jpg). Also we have attached log file(Please refer ErrorLogFile.txt). 

We are using below apache poi libraries – 
1. poi-ooxml-5.2.3.jar
2. poi-5.2.3.jar
3. poi-ooxml-full-5.2.3.jar

Please respond as soon as possible.
Comment 1 Matthias Raschhofer 2023-09-08 14:48:53 UTC
Hi Komal,

Could you please attach the input xlsx file as well? Otherwise nobody will be able to reproduce your test case.

Thanks.
Comment 2 Komal Anil Ghare 2023-09-11 06:24:08 UTC
Created attachment 39003 [details]
Zip containing input file and output file.
Comment 3 Komal Anil Ghare 2023-09-11 06:27:42 UTC
Hi Matthias,

Please find the input file as well as output file. After opening output file 2 warnings appear because of setDefaultSubtotal() method that we used in our code. please click yes to access the pivot table result.


Thanks, 
Komal Ghare
Comment 4 Matthias Raschhofer 2023-09-11 09:50:29 UTC
Created attachment 39006 [details]
Updated the example code to initialize the pivot field items and the pivot cache definition

Hi Komal,

The pivot table support in Apache POI is rather limited. When creating a new pivot table, POI only creates the general structure and data references. Excel will then refresh the pivot data upon opening the file.

Regarding your issue, see this StackOverflow post for further helpful information: https://stackoverflow.com/questions/37305976/apache-poi-xssfpivottable-setdefaultsubtotal/40480654#40480654

It is not enough to set the defaultSubtotal field, which essentially just updates the underlying XML attribute. In order to remove the subtotal row from the pivot table, the pivot field items have to be adapted as well.

I adapted your example code (PivotTableCode.java) to add the necessary changes.
Comment 5 Komal Anil Ghare 2023-09-11 13:06:48 UTC
Hi Matthias,


Thank you for providing the updated code.
But it has some limitation, after opening file if we add new fields to pivot table through excel then it shows subtotal for those fields which will not resolve our problem.


Thanks,
Komal Ghare
Comment 6 Matthias Raschhofer 2023-09-11 15:54:42 UTC
Created attachment 39007 [details]
Remove subtotal rows for all pivot fields.

Hi Komal,

For pivot fields which are not initially used as rows, you can just set the defaultSubtotal to false anyways. This way, if fields are added to the table in excel, there will not be a subtotal row.

Please check out the updated code.

Br, Matthias
Comment 7 Komal Anil Ghare 2023-09-12 04:20:32 UTC
Hi Matthias,


Thanks for the updated code. 


Thanks,
Komal Ghare