简体   繁体   中英

Apache Poi set data field style for pivot table

I need to set the style for 2 sheets in 1 workbook, but I have a total of 6 sheets. I can set the style for all with

wb.createDataFormat().putFormat((short) 0, "_($* #,##0.00_);_($*(#,##0.00);_($* \"-\"??_);_(@_)");

,but this is not what I want, since its applying the style to a sheet which doesn't represent data about money. Does anyone has an idea on how to set the style only for specific sheets?
PS: the style should apply to pivot tables

So i actually found a solution on setting the format of the data area.

How to set PivotTable Field Number Format Cell with Apache POI

on this link the answer is posted. simply use the setFormatDataField method to set the style. you can also define your own format as example like this short accounting = wb.createDataFormat().getFormat("_($* #,##0.00_);_($* (#,##0.00);_($* \\"-\\"??_);_(@_)"); and set it with a call like this setFormatDataField(pivotTable, 2, accounting); . I hope this helps some more people who are searching for an answer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM