0
我試圖從Excel中的每張工作表檢索特定值。 該代碼適用於測試Excel工作簿,但不適用於試圖檢索的Excel文件。從Excel中檢索值Apache POI
遇到的錯誤是,
"Exception in thread "AWT-EventQueue-0" org.apache.poi.ss.formula.FormulaParseException: Specified named range 'Table156723451819202122232434567891011121314151619216710111213162024254567101718193456781112131623242528234789101314151619202128910111215234567891011121314161718192021222324252627282930312345678910111213141516171819202122232425262728293032234567891011140' does not exist in the current workbook."
目標Excel工作簿只有1個月張(1jan,2jan ...) 而細胞靶向IM看起來像這樣:
目標小區公式如下:= SUM(D23:D24)
下面是我的代碼:
for(int i=0; i<=30; i++){
Sheet sheet = wb.getSheetAt(i);
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
CellReference cellReference = new CellReference("D25");
//CellReference cellReference = new CellReference("A4");
Row row = sheet.getRow(cellReference.getRow());
Cell cell = row.getCell(cellReference.getCol());
//System.out.println("i:"+row.getCell(cellReference.getCol()));
//CellValue cellValue = evaluator.evaluate(cell);
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;
}
我曾試圖把我的測試Excel中相同的公式,它工作正常。 因爲我長時間呆在這裏,所以請給予指導。非常感謝!