首先 为什么这个时间还用1.0.6 因为用了2.4以上 jdk6运行起来很难受 嗯 然后之前用的好好的 那个公式突然 还要点进去再按回车才会生效 那不给客户打死 然后就找博客 copy了一份通用的方法
/**
*
* 重新设置单元格计算公式20180615
*
* */
public static void resetCellFormula(HSSFWorkbook wb)
{
HSSFFormulaEvaluator e = new HSSFFormulaEvaluator(wb);
int sheetNum = wb.getNumberOfSheets();
for (int i = 0; i < sheetNum; i++)
{
HSSFSheet sheet = wb.getSheetAt(i);
int rows = sheet.getLastRowNum() + 1;
for (int j = 0; j < rows; j++)
{
HSSFRow row = sheet.getRow(j);
if (row == null)
continue;
int cols = row.getLastCellNum();
for (int k = 0; k < cols; k++)
{
HSSFCell cell = row.getCell(k);
// if (cell != null)
// System.out.println("cell["+j+","+k+"]=:"+cell.getCellType());
if (cell == null)
continue;
if (cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA)
{
cell.setCellFormula(cell.getCellFormula());
// System.out.println("----公式:"+cell.getCellFormula());
cell = e.evaluateInCell(cell);
// System.out.println("-----------"+cell.getNumericCellValue());
}
}
}
}
}