I have tried the scenario with both ver 8.6.1 and 20.6 but could not observe any difference as both the output files show #NAME when it is opened and then I need to enable the macros. Could you please share which version of MS Excel are you using and other environment details? We will try to reproduce the issue here and provide assistance accordingly.
machine : Windows 10, Netbeans 12, JDK 1.8 (Oracle)
λ java -version
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)
The maven project source & target are for 1.8 .
Excel 2010
These are my steps that i follow to reproduce the issue :
Excel : clean all trusted documents
run the app and generate the “Classeur_Copié.xlsm” file
Open the generated file, Excel asks me to click to validate “macros”
I click to “validate”
the macro runs fine
I quit Excel without saving
With the v20.6 :
7. i open the generated file again : Excel doesnt ask me to validate macro; and #NAME appears in the cell
With the v8.6.1:
7. i open the generated file again : Excel doesnt ask me to validate macro; and the cell is correctly displayed.
Between the two tests, I build the project after changing Cells version.
Theses steps are more simpler if i speficy to Excel that the destination directory is trusted. But the result is the same between the two versions of Cells.
@uetac,
We have observed this issue and logged it in our database for further investigation and fix. You will be notified here once any update is ready to share.
This issue is logged as CELLSJAVA-43236 - Workbook calculate formula does not show value after enabling macro while opening output file next time
@uetac,
You may please modify the code as follows and test the scenario again. It will show values fine when second time output file is opened in MS Excel.
try {
Workbook wb = new Workbook("Classeur_Base.xlsm");
wb.getWorksheets().get(0).getCells().get(1, 3).setValue("Hey");
wb.calculateFormula();
wb.getSettings().setReCalculateOnOpen(true);//<=======NOTE THIS LINE
wb.save("Classeur_Copié_20.6.3.xlsm");
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
Good to know that your issue is sorted out by the suggested line of code. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.