0

Apache poiを使用してワークブックにIRR式を適用しており、Excelシートで値を確認できます。しかし、#NUM として値を取得しています! FormulaEvaluator を使用して値を取得しようとしたとき。例

    Cell cell = contentRow.createCell(3);
    cell.setCellFormula(irrFormula + "*12");        
    FormulaEvaluator evaluator = sheet.getWorkbook().getCreationHelper().createFormulaEvaluator();
    CellValue cellValue = evaluator.evaluate(cell);
    if (Constants.NUM_ERROR.equals(cellValue.formatAsString().trim())) {
        calculateTotal.setIrrTotal(Constants.IS_NAN);
    }else {
        double irrValue = cellValue.getNumberValue();
    }

また、値を取得するために以下のアプローチを試みましたが、値を取得していません。あなたの提案をしてください

for(Cell cell : row) {
     if(cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
        System.out.println("Formula is " + cell.getCellFormula());
        switch(cell.getCachedFormulaResultType()) {
            case Cell.CELL_TYPE_NUMERIC:
                System.out.println("Last evaluated as: " + cell.getNumericCellValue());
                break;
            case Cell.CELL_TYPE_STRING:
                System.out.println("Last evaluated as \"" + cell.getRichStringCellValue() + "\"");
                break;
        }
     }
 } 

cell.getRawValue();
4

0 に答える 0