本帖最后由 Matthew.Xue 于 2025-5-8 09:58 编辑
确实存在这种情况,但是也比较好解决,在copy完成之后,遍历pivotTable,获取所有单元格的formula,如果有formula,则获取该单元格的值,并且删除tmpPivotTable中相同坐标单元格的formula,设置为值即可。
- IWorksheet tmpPivotTable = tmpWorkbook.getWorksheets().get("PivotTable");
- IRange usedRange = pivotTable.getUsedRange();
- for(int r = usedRange.getRow();r<usedRange.getRow()+usedRange.getRowCount();r++) {
- for(int c = usedRange.getColumn();c<usedRange.getColumn()+usedRange.getColumnCount();c++) {
- String f = pivotTable.getRange(r,c).getFormula();
- if(!f.isEmpty()) {
- System.out.println(r+","+c+","+f);
- Object value = pivotTable.getRange(r,c).getValue();
- tmpPivotTable.getRange(r,c).setFormula(null);
- tmpPivotTable.getRange(r,c).setValue(value);
- }
- }
复制代码
|