java 读取excel公式数据

释放双眼,带上耳机,听听看~!

FileInputStream fis = new FileInputStream(“c:/temp/test.xls”);
Workbook wb = new HSSFWorkbook(fis); //or new XSSFWorkbook(“c:/temp/test.xls”)
Sheet sheet = wb.getSheetAt(0);
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();

// suppose your formula is in B3
CellReference cellReference = new CellReference(“B3”);
Row row = sheet.getRow(cellReference.getRow());
Cell cell = row.getCell(cellReference.getCol());

CellValue cellValue = evaluator.evaluate(cell);

switch (cellValue.getCellType()) {
case Cell.CELL_TYPE_BOOLEAN:
System.out.println(cellValue.getBooleanValue());
break;
case Cell.CELL_TYPE_NUMERIC:
System.out.println(cellValue.getNumberValue());
break;
case Cell.CELL_TYPE_STRING:
System.out.println(cellValue.getStringValue());
break;
case Cell.CELL_TYPE_BLANK:
break;
case Cell.CELL_TYPE_ERROR:
break;

// CELL_TYPE_FORMULA will never happen
case Cell.CELL_TYPE_FORMULA: 
    break;

}

【转自慕课】https://www.imooc.com

JAVA

北大青鸟租车系统(六步骤,带来些微不同的思路。可以和答答系统对照着看)

2022-3-3 7:06:58

JAVA

租车系统简易代码个人思路

2022-3-3 7:11:54

搜索