0

im using openpyxl to edit an excel file that contains some formulas in certain cells. Now when i populate the cells from a text file, im expecting the formula to work and give me my desired output. But what i observe is that the formulas get removed and the cells are left blank.

ZInj
  • 341
  • 2
  • 9

2 Answers2

1

I had the same problem when saving the file with openpyxl: formulas removed. But I pointed out that some intermediate formulas were still there.

After some tests, it appears that, in my case, all formulas which are displaying blank result (nothing) are cleaned when the save occured, unlike the formulas with an output in the cell, which are preserved.

ex : =IF((SUM(P3:P5))=0;"";(SUM(Q3:Q5))/(SUM(P3:P5))) => can be removed when saving because of the blank result

ex : =IF((SUM(P3:P5))=0;"?";(SUM(Q3:Q5))/(SUM(P3:P5))) => preserved when saving

for my example I'm using openpyxl-2.0.3 on Windows. Open and save function calls are :

self._book = load_workbook("myfile.xlsx", data_only=False)

self._book.save("myfile.xlsx")

mbr
  • 21
  • 2
0

openpyxl does currently not support reading of formulas. Ie. If you read your file and write it back, all formulas are removed. There is an active feature request in bitbucket tough.

Herbert Poul
  • 4,512
  • 2
  • 31
  • 48