Apache POI 如何将工作簿样式应用于所有数据透视表.我如何排除工作表? [英] Apache POI how to apply Workbook Style to all Pivot Tables. how do i exclude sheets?

查看:31
本文介绍了Apache POI 如何将工作簿样式应用于所有数据透视表.我如何排除工作表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在开发一个程序,该程序读取文本文件并将此数据写入 Excel 工作簿.写入数据后,我从数据创建数据透视表.为了在数据透视表中获得样式,我设置了整个工作簿样式,为什么它只适用于具有数据透视表的工作表而不适用于数据表.现在我想从工作簿样式中排除一张带有数据透视表的工作表.有没有办法排除一张工作表或为需要它的工作表设置样式?

So i am working on a program which reads a text file and writes this data in an excel workbook. after the data is written i create pivot tables from the data. to get style in the pivot table i've set the whole workbook style which somewhy only applys to the sheets with the pivot tables and not the data sheets. now i want to exclude one sheet with pivot table from the workbook style. is there a way to exclude one sheet or set the style for the sheets which need it?

工作簿样式代码:

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

数据透视表:

CellReference cr = new CellReference("A1");
CellReference c1 = new CellReference(0, 0);
CellReference c2 = new CellReference(data.getPhysicalNumberOfRows() - 1, data.getRow(0).getLastCellNum() - 1);

AreaReference ar = new AreaReference(c1, c2);
XSSFPivotTable pivotTable = sheet.createPivotTable(ar, cr, data);

pivotTable.getCTPivotTableDefinition().getPivotFields().getPivotFieldArray(4).setAxis(STAxis.AXIS_COL);
pivotTable.getCTPivotTableDefinition().getPivotFields().getPivotFieldArray(4).addNewItems();
pivotTable.getCTPivotTableDefinition().getPivotFields().getPivotFieldArray(4).getItems().addNewItem()
        .setT(STItemType.DEFAULT);

pivotTable.getCTPivotTableDefinition().addNewColFields().addNewField().setX(4);

pivotTable.addRowLabel(10);
pivotTable.addRowLabel(11);
pivotTable.addRowLabel(1);
pivotTable.addColumnLabel(DataConsolidateFunction.COUNT, 0);

我已经尝试为工作表中的单元格设置样式,但没有成功.有什么建议?

i already tried to set the style for the cells in the sheet but didn't work. any suggestions?

推荐答案

所以我在这里找到了解决方案:Apache Poi 设置数据透视表的数据字段样式.这个问题也可能更准确地说明我想要实现的目标

so i found an solution here: Apache Poi set data field style for pivot table. this question might also be more accurate on what i wanted to achieve

这篇关于Apache POI 如何将工作簿样式应用于所有数据透视表.我如何排除工作表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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