简体   繁体   English

使用Java在Excel中更新公式

[英]Update a formula in excel using Java

I'm starting to build an app (in java) and I am having some problems.I'm pretty new with all that and I'm getting a little lost. 我开始构建一个应用程序(使用Java),但遇到了一些问题,所有这些我都是新手,我有点迷路了。

I am trying to export some info to an excel template. 我正在尝试将一些信息导出到excel模板。 I have no problem with that, but the template has some excel formulas. 我对此没有问题,但是模板具有一些excel公式。

When I open the template all the info is there, but in order to see the results of the formulas i have to copy/paste all the values given by the app. 当我打开模板时,所有信息都在那儿,但是为了查看公式的结果,我必须复制/粘贴应用程序给定的所有值。

I've found a sentence to update all the formulas 我找到了更新所有公式的句子

workbookInfDef.getCreationHelper().createFormulaEvaluator().evaluateAll();

But it doesn't work. 但这是行不通的。 An error stop happens with it and the app collapses... 发生错误停止,应用程序崩溃了...

I would be really greatfull if anyone could help me! 如果有人可以帮助我,我将非常的高兴!

f you're using XSSF workbooks, you can re-evaluate all formula cells as follows: 如果您使用的是XSSF工作簿,则可以如下重新评估所有公式单元格:

XSSFFormulaEvaluator.evaluateAllFormulaCells(workbook)

A similar API exists if you're using an HSSF workbook: 如果您使用的是HSSF工作簿,则存在类似的API:

HSSFFormulaEvaluator.evaluateAllFormulaCells(workbook)

Or, depending on exactly how you're set up and what specifically you're trying to get accomplished, you should be able to find your solution here 或者,具体取决于您的设置方式以及您要达到的目标,您应该可以在这里找到解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM