java - 如何在不使用 apache poi 的情况下从工作簿单元格中获取公式值
问题描述
我正在使用 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();
解决方案
推荐阅读
- google-sheets - 是否可以在 Google 的连接表中编写 vlookup 函数?
- flutter - 如何在 Flutter 中消费 PubNub 聊天消息?
- r - plot.new() 中的错误:R markdown 中的图形边距太大
- vue.js - VueJS - 如果选项少于 2 个,则禁用选择下拉菜单
- javascript - 如何使用 python selenium 从 chrome 控制台中查找 JS 元素
- oracle - 如何在 Oracle 中刷新 SELECT 的物化视图?
- android - Android无障碍服务-“不支持当前系统语言”
- javascript - 使用网络音频 api 播放 pcm 的正确方法是什么
- android - 是 ViewModel 还是 Fragment 中的 OnClickListener 和 OnLongClickListener?
- actions-on-google - 如何通过 REST API 请求创建或更新类型条目?