问题描述
我已经创建了一个工作表, out.xls ,它的单元格D6 = D5 * 2和D5设置为1.我的问题是,当我将值插入到J5中的D5中时,D6永远不会计算。 D6只是在Excel中插入1到D5时初始计算的值。
I have created a worksheet, out.xls which had cell D6=D5*2 and D5 set to 1. My issue is that when I plug a value into D5 in jxl, D6 never calculates. D6 simply holds on the value it initially calculated when I plugged in 1 to D5 in excel.
注意:我有一个更大的编程问题,我正在努力解决,这只是一个非常缩小的版本,以减少错误。
note: I have a much larger programming problem that I am trying to tackle, this is just a very scaled down version to reduce error.
这是我第一次使用Jexcel,而我去年刚刚学习了java,所以任何帮助都不会感谢。我花了6个小时昨天尝试在网上找到一个答案,但没有效果。
This is my first time ever use Jexcel and I only just learned java this last year, so any help would be appreciated. I spent 6 hours yesterday trying to find an answer on the web, but to no avail.
输出附在代码下面
代码(省略主要和导入)
the output is attached below the code
Code: (left out the main and imports)
WorkbookSettings custom= new WorkbookSettings();
custom.setRationalization(true);
custom.setRefreshAll(true);
custom.setUseTemporaryFileDuringWrite(true);
Workbook workbook = Workbook.getWorkbook(new File("out.xls"),custom);
WritableWorkbook copy = Workbook.createWorkbook(new File("output.xls"), workbook);
WritableSheet sheet2 = copy.getSheet(0);
SheetSettings customsheetsettings=new SheetSettings(sheet2);
customsheetsettings.setAutomaticFormulaCalculation(true);
Number number = new Number(3, 4, 3);
sheet2.addCell(number);
copy.write();
copy.close();
workbook.close();
Workbook workbook2 = Workbook.getWorkbook(new File("output.xls"));
Sheet sheet=workbook2.getSheet(0);
System.out.println("D5:"+sheet.getCell(3,4).getContents());
FormulaCell formula5=(FormulaCell) sheet.getCell(3,5);
System.out.println("Formula:"+formula5.getFormula());
System.out.println("D6:"+formula5.getContents());
NumberFormulaCell nfc=(NumberFormulaCell)sheet.getCell(3, 5);
System.out.println(nfc.getValue());
workbook2.close();
输出:
D5:3
Formula:D5*2.0
D6:2
2.0
推荐答案
JExcel只允许读取或写入Excel文件,并给出内容的Java表示的Excel文件。它不会替代Excel。
JExcel only allows to read or write Excel files, and give a Java representation of the content of an Excel file. It will not substitute for Excel.
添加公式时,将在Excel中打开生成的文件时计算此公式,但仅在Excel中。单元格不是由JExcel计算的。
When you add a formula, this formula will be computed, but only in Excel, when you open the generated file in Excel. The cell is not computed by JExcel.
这篇关于Jexcel公式计算错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!