Java读取Excel表格公式对应的值:
//伪代码org.apache.poi
String fileName = file.getOriginalFilename();
//判断excel版本
if(fileName.endsWith("xls")) Workbook wb = new HSSFWorkbook(file.getInputStream());
if(fileName.endsWith("xlsx")) Workbook wb = new XSSFWorkbook(file.getInputStream());
Sheet sheet = wb.getSheetAt(i);
Row row = sheet.getRow(i);
//判断表格内容格式,是否是公式
if(row.getCell(i).getCellType().equals(CellType.FORMULA)){
if(row.getCell(i).getCachedFormulaResultType().equals(CellType.FORMULA)) Double d = row.getCell(i).getNumericCellValue();
if(row.getCell(i).getCachedFormulaResultType().equals(CellType.STRING)) String s = row.getCell(i).getRichStringCellValue();
}
else if(row.getCell(i).getCellType().equals(CellType.NUMERIC)) Double d = row.getCell(i).getNumericCellValue();
else if(row.getCell(i).getCellType().equals(CellType.STRING)) String s = row.getCell(i).getStringCellValue();