我修改了基本example以在新工作表中创建数据透视表 . 但是在打开新的xlsx文件时,我收到一个错误( Excel found unreadable content in... 后跟:
Removed Part: /xl/pivotTables/pivotTable1.xml part with XML error. (PivotTable view) Load error. Line 2, column 561.
Removed Records: Workbook properties from /xl/workbook.xml part (Workbook)
)
这是我修改的代码段:
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet("plain");
//Create some data to build the pivot table on
setCellData(sheet);
XSSFSheet sheet2 = wb.createSheet("pivot");
XSSFPivotTable pivotTable = sheet2.createPivotTable(new AreaReference("plain!$A$1:$D$4", null), new CellReference("pivot!$A$1"));
//Configure the pivot table
//Use first column as row label
pivotTable.addRowLabel(0);
//Sum up the second column
pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 1);
//Set the third column as filter
pivotTable.addColumnLabel(DataConsolidateFunction.AVERAGE, 2);
//Add filter on forth column
pivotTable.addReportFilter(3);
我已经通过代码进行了调试,并没有看到明显的问题......
关于如何处理这个问题的想法?或者如果这是图书馆的错误?
谢谢
EDIT
问题是从上面代码中的单元格引用A1( new CellReference("pivot!$A$1") )开始 . 看来,如果我们从A1开始,表单上没有足够的空间来做其他格式化的透视网格 . 所以将其改为A5就可以了 . 虽然我仍然认为POI应该明确阻止人们通过抛出错误来做到这一点