在读取excel表格时,单元格内是公式的情况下读取到的是string类型的公式内容,要想直接读取到公式的计算结果(即单元格数值),需另外写方法读取。
方法一:在经判断为公式后,进入case 2,读取计算结果,再通过获取行列调用;
case 2: {
try {
cellValue = cell.getStringCellValue();
} catch (IllegalStateException e) {
cellValue = String.valueOf(cell.getNumericCellValue());
}
break;
}
public static Workbook readExcelWorkbook(Workbook workbook, FinanceCostingDTO financeCostingDTO) {
// 循环解析sheet页
for (int sheetNum = 0; sheetNum < workbook.getNumberOfSheets(); sheetNum++) {
// 获取第i个sheet页
Sheet sheet = workbook.getSheetAt(sheetNum);
// 校验sheet是否合法
if (isNull(sheet)) {
continue;
}
int firstRowNum = sheet.getFirstRowNum();
// 获取第一行数据