使用easypoi导出excel 带公式不生效,
导出内容为文本类型,需要点击一下之后才生效。
不是自己期望的样子,找了好多解决方案,最终处理方式:

Workbook workbook = ExcelExportUtil.exportExcel(params, map);
//公式处理
//刷新公式
HSSFFormulaEvaluator hssfFormulaEvaluator = new HSSFFormulaEvaluator((HSSFWorkbook) workbook);
//获取sheet页
Sheet sheet0 = workbook.getSheetAt(0);
sheet0.forEach(x->{
if( x.getRowNum()!=0 && x.getRowNum()!=sheet0.getLastRowNum()) {
//找到指定单元格
Cell cell6 = x.getCell(6);
if(cell6 != null ){
//设置格式为公式
cell6.setCellFormula(cell6.getStringCellValue());
hssfFormulaEvaluator.evaluateFormulaCell(x.getCell(6));
}
}
});
workbook.setForceFormulaRecalculation(true);
解决Easypoi导出Excel时公式不自动计算的问题,通过HSSFFormulaEvaluator刷新公式,实现导出后即可见计算结果。
2257

被折叠的 条评论
为什么被折叠?



