使用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);