Apache Poi 为数据透视表设置数据字段样式 [英] Apache Poi set data field style for pivot table

查看:33
本文介绍了Apache Poi 为数据透视表设置数据字段样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为 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.

如何设置数据透视表字段编号格式带有 Apache POI 的单元

在此链接上发布了答案.只需使用 setFormatDataField 方法来设置样式.你也可以定义你自己的格式作为这样的例子 short accounting = wb.createDataFormat().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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆