Apache Poi为数据透视表设置数据字段样式 [英] Apache Poi set data field style for pivot table
问题描述
我需要在1个工作簿中设置2张的样式,但是我共有6张。我可以使用
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);_($* \"-\"??_);_(@_)");
,但这不是我想要的,因为它将样式应用于不代表数据的表格。任何人都有一个想法如何设置样式只适用于特定的工作表?
PS:样式应该适用于数据透视表
,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.
在这个链接上,答案发布,只需使用 setFormatDataField
方法来设置样式,你也可以定义你自己的格式,就像这样 short accounting = wb.createDataForm at()。getFormat(_($ *#,## 0.00 _); _($ *(#,## 0.00); _($ * \-\ _));
,并使用这样的调用 setFormatDataField(pivotTable,2,accounting);
设置它。我希望这有助于更多的人正在寻找答案
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
这篇关于Apache Poi为数据透视表设置数据字段样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!