excel asks if i want to save changes on close xlsx with formulas
C++ library for creating XLSX files for MS Excel 2007 and above.
Brought to you by:
oxod,
programmeralex
Hello and thanks for excel writer library.
The minimal code to reproduce the issue is this:
It saves file, file can be opened normally, but after user closes file (no changes were made), excel asks if he should save changes. I attached example.
Very likely it is an issue of the not-100% implementation of the Excel internal structures in generated file. When Excel opens generated file, it prepared these structures automatically and then wants to save them. In you case it might be result of the formula calculation.
My suggestion is to save generated file from Excel if possible.
It is possible, but i have to do it every time? Can it be fixed?
In general better to re-save generated file from Excel. There are no problems with reading for the Excel , but there are no guarantee concerning third party software. I have strange issues with some.
100% implementation of the xlsx for me looks problematic, however it is question to Alexandr Belyak.
"...but there are no guarantee concerning third party software. I have strange issues with some."
Is this software available for free? Can you provide examples of such software and corresponding xlsx files? I'm trying to improve the compatibility of the files generated by SimpleXlsxWriter. It may be possible to improve this situation further.
This is commercial software, and producer is not very cooperative in such matters.
There are chances that issue related to the resolved problem of the actual size of the sheet, but I cannot prove it at that moment.
It looked like this: I create new project in this software, it is using number of the xlsx files to fetch data. At creation everything looks fine. But if I save project and than reopen, it cannot fetch data again. So I started re-save xlsx automatically and insisted other users to do it.
Hello everyone and thanks to Alexander Arkhipov for the detailed description of the problem.
E.Naumovich is right with the cause and, I think, right with the proposed solution.
The fact is that Excel saves a cache with the results of formula calculations in the xlsx file. This is necessary to speed up the work.
SimpleXlsxWriter does not contain a formula calculator and does not fill in the corresponding cache in the xlsx file. There are no plans to add a formula calculator to the library yet.
Therefore, I believe that E.Naumovich suggested a good solution with resaving the file using Excel.
Today i got some free time to investigate problem further.
I created my test 1.xlsx with SimpleXlsxWriter, copyed it, and saved using excel (i am using excel 2010).
Then i compared changes between these two files:
It appears that they differs in two files:
.xlsx\xl\workbook.xml
According to this calcid is a formulas engine id, if its lower than current, document formulas are recalculated. I think its OK to use 999999 to avoid recalculation due to newer Excel client program version.
.xlsx\xl\worksheets\sheet1.xml
where v tag means computed formula value.
Sooooo. To make excel stop complaining about unsaved formulas its enough to save formula and a value inside a cell.
Last edit: Alexander Arkhipov 2023-08-19
Thank you for the research and its detailed description. In general, you have discovered what E.Naumovich and I wrote about earlier.
I think it's a dirty hack. Today it can work, and tomorrow an Excel update will be released with a detailed check of this value and when opening the file, a message will appear that the xlsx file is corrupted. It is not necessary to assume that Excel does not check parameter values well.
In addition, if you incorrectly calculate the value of the formula, you can seriously harm the end user.
This trick can be applied to simple formulas, but with large formulas there may be nuances, since you need to know the features of the Excel computing engine. Otherwise, as I wrote above, you can seriously harm the end user.
I think it's not worth making the changes you suggested to the library. But you have the right to modify the library yourself to suit your needs. By and large, you have already figured out the main things.
Ok i understand your point. But my small project uses just formulas of type "=SUM("A1:C1")" so i will make some patches to calculate resulting value and store it.
Ok, thanks for understanding.
If you have any difficulties with modifying the library, write here, I will try to help.