I could not find the issue using your Excel files. I used the following sample code, which works fine. The cell values are not mismatched and are the same before and after calculating formulas.
e.g. Sample code:
@amjad.sahi : I have attached two files. they both have same input values and when I use the code mentioned above I get different results. you can see the output sheet for both the excels they are mismatched.
I got same (output) results when using your both files. Please run the sample code (I shared in my previous post, please update file path to the Excel file(s) for your environment) and paste the console output for our reference. By the way, could you please also print the Aspose.Cells version that you are using in your application, see the document with example on how to print/get the version of Aspose.Cells for Java that is being used on your end dynamically.
@gkamdar
Through further testing, we found that if you manually calculate the formula in Excel, you will also get the same result. This situation may be caused by not calling the formula calculation during file creation, resulting in some data errors. You can verify by manually calculating the formula in Excel and saving the file, and then running the test code. You will get the same result.
@John.He: what do you mean by “This situation may be caused by not calling the formula calculation during file creation,”
I have tried doing the below approch and it doesn’t work
call the workbook.calculateFormula(); when I am creating the file?
and then again
workbook.refreshDynamicArrayFormulas(true, new CalculationOptions());
workbook.calculateFormula();
I can see the mismatch for the same input when I run for 1st time. 2nd execution and henceforth it is stable.
Any inputs will be really helpful
@John.He : through manual formula calculation I do not get same result, it is different. any aspose settings that need to be done? We are finding this scenario for other excels as well where the 1st run and 2nd run json do not match and after that it is same.
@gkamdar
When opening your template in ms excel and make ms excel calculate the formulas(such as press “Calculate Now”), we found we can get the same values with what we got by code(printed by the code such as at here). Would you please point out those cells which you found mismatched?
For those formulas that may give different results for the first and second calculation, the reason should be that there are some circular references, for such kind of situation, the calculated result depend on the count of iteration.
@johnson.shi : I did “calculate now” and I get the same results.
but my question here is why I don’t get the same values when I am calculating using the workbook.calculateFormula() method ?
The excel that I shared with you is saved after using the “workbook.calculateFormula()” method
Can you pls elaborate on this
the reason should be that there are some circular references, for such kind of situation, the calculated result depend on the count of iteration.
We get same results (and don’t get mismatches) when calculating formulas by Aspose.Cells API and MS Excel (manual) for your Excel spreadsheets. Could you please provide details of your environment (OS details with locale/regional settings, MS Excel version, JDK version, etc.).
@amjad.sahi : Excel version that I am using version 2302, JDK version jdk1.8.0_341.
If I run the below code snippet for the file attached it will give me consistent results
workbook.getSettings().getFormulaSettings().setEnableIterativeCalculation(true);
workbook.refreshDynamicArrayFormulas(true, new CalculationOptions());
workbook.calculateFormula();
workbook.calculateFormula();
workbook.calculateFormula();
I have to use calculateFormula thrice to get consistent results.
if you use the file attached, test-file.zip (1.4 MB)
run it with below 3 scenarios
once workbook calculation
twice workbook calculation
thrice workbook calculation
you will see there are different results for the code for each scenario
System.out.println(cells.get(“E167”).getStringValue());
System.out.println(cells.get(“F167”).getStringValue());
System.out.println(cells.get(“G167”).getStringValue());
Please let me know if you need any more details to replicate this
@gkamdar
By using sample code and files for testing, we can reproduce the issue. Found different incorrect results obtained after calling multiple formula calculation.
Test code as follows:
0
0
0
After calculating formulas=====once
111,429
169,997
210,363
After calculating formulas=====twice
163,568
204,450
235,435
After calculating formulas=====Three times
163,568
163,568
163,568
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): CELLSJAVA-45780
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
This is to inform you that your issue (logged as “CELLSJAVA-45780”) has been resolved. The fix/enhancement will be included in our upcoming release (Aspose.Cells v24.1) that we plan to release in the first half of January 2024. You will be notified when the next version is released.
@amjad.sahi : I am using the v24.1 and see another mismatch. Attached are the files. I have marked the mismatched cells in red in “output sheet”. mismatch_example.zip (2.8 MB)
I am running v24.1 aspose cells with the below code
workbook.getSettings().getFormulaSettings().setEnableIterativeCalculation(true);
workbook.refreshDynamicArrayFormulas(true, new CalculationOptions());
workbook.calculateFormula();
Can you pls have a look and let me know if you need any more info
@gkamdar
By using sample files for testing, we can reproduce the issue. It was found that some cells obtained incorrect results after calling the formula calculation.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): CELLSJAVA-45838
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.