How to set formula value in openpyxl

I am trying to write a simple tool to work with .csv and .xlsx files. The idea is to read the data as .csv, add some changes and export to .xlsx with the changes added. Everything works for me, but when I try to write a .xlsx file (using openpyxl in Python) I have problems. When I open a document in LibreOffice Calc or Gnumeric, some fields are not displayed. The fields I'm having trouble with include formulas. When I click on them, the formulas are entered correctly in the field, but nothing appears in the field. If I retype the character in the formula it evaluated and the value appears.

I'm having a problem in the underlying .xml of a sheet and the cells obviously don't have a cache. But I also noticed that it doesn't always have the correct data type. I tried to fix this by explicitly setting the type to the formula, but no luck.

What I am using now to set a cell:

cell = ws.cell(column=i,row=j)
cell.set_explicit_value(value=val,data_type=cell.TYPE_FORMULA)

      

+3
python export-to-excel openpyxl


source to share


No one has answered this question yet

Check out similar questions:

5116
How can I check if a file exists without exceptions?
4268
How to combine two dictionaries in one expression?
3790
How can I safely create a subdirectory?
3474
How to list all files in a directory?
3428
How to sort a dictionary by value?
3235
How to check if a list is empty?
2621
How do I create a chain of function decorators?
4
openpyxl returns empty cell values ​​for a series of formulas
1
OpenPyXl removes boot formulas



All Articles
Loading...
X
Show
Funny
Dev
Pics