Skip to content Skip to sidebar Skip to footer

Excel Removing Valid Formula Inserted By Python

I am trying to generate an excel xlsx report in Python, using openpyxl, but there is a problem. Excel keeps removing formula from my sheet in a few specific cells. I printed what i

Solution 1:

Please pay attention to the warning in the documentation: http://openpyxl.readthedocs.io/en/default/usage.html#using-formulae

NB you must use the English name for a function and function arguments must be separated by commas and not other punctuation such as semi-colons.

Solution 2:

You can use below syntax to update a formula in excel, or make use to use r in front of string, it avoids you to have backslashes in the formula

I tested that out, works perfectly fine:

formula = r'=CONCATENATE($N$2,"=",N3,";", $O$2,"=",O3,";", $P$2,"=",P3,";", $Q$2,"=",Q3,";", $R$2,"=",R3,";",$S$2,"=",S3,";",$T$2,"=",T3,";", $U$2,"=",U3,";")'

test_case_sheet.cell(row=row_index, column=header_col_map_dict['TestDataKey']).value = formula

Post a Comment for "Excel Removing Valid Formula Inserted By Python"