2

新しいExcelファイルを保存するときに問題が発生します。保存されたときに数式がそれ自体を計算するようにしたいのですが、現時点では、Excelファイルで文字列を返しているだけです。式は正しいです。を機能させるための正確な方法はわかりませんFormulaEvaluator

ここに、文字列を返す数式を入力します。

dataRow1.createCell((short)5).setCellValue("=VLOOKUP(A"+rowCountVlookup+",'C:\\Users\\Admin\\Documents\\JCreator LE\\MyProjects\\WordCount\\classes\\[Pricing.xlsx]Sheet1'!$B$3:$E$41,4, FALSE)*E"+rowCountVlookup+"");

どんな助けでも大歓迎です。

4

2 に答える 2

1

最終的にはなんとか解決できました。

String strFormula = "ROUND((VLOOKUP(A"+rowCountVlookup+",'C:\\Users\\Admin\\Desktop\\[pricing.xlsx]Sheet1'!$B$3:$E$41,4, FALSE)*E"+rowCountVlookup+"),2)";
                            dataRow1.createCell((short)5).setCellType(Cell.CELL_TYPE_FORMULA);
                            dataRow1.createCell((short)5).setCellFormula(strFormula);
于 2012-06-07T10:22:36.840 に答える
0

このコードを使用して数式を評価します

//I use an instance of the workbook for the Excel workbook I'm working at the moment
Workbook wbook;

private CellValue formulaEvaluation(Cell cell) {
    FormulaEvaluator formulaEval = wbook.getCreationHelper().createFormulaEvaluator();
    return formulaEval.evaluate(cell);
}

public Double obtieneObjetoNumericoCelda(Cell cell) {
    Double dblValue = null;
    if (cell != null) {
        switch(cell.getCellType()) {
        case Cell.CELL_TYPE_NUMERIC:
            dblValue = cell.getNumericCellValue();
            break;
        case Cell.CELL_TYPE_FORMULA:
            CellValue objCellValue = formulaEvaluation(cell);
            if (objCellValue.getCellType() == Cell.CELL_TYPE_NUMERIC) {
                dblValue = objCellValue.getNumberValue();
            }
            break;
        }
    }
    return dblValor;
}
于 2012-06-06T13:54:47.213 に答える