Apache Poi set data field style for pivot table

会有一股神秘感。 提交于 2019-12-24 08:23:16

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/40848133/apache-poi-set-data-field-style-for-pivot-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!