openpyxl changes cells defined by a formula to NaN unless manually saved in excel

16 Views Asked by At

When using the following code, other cells defined by a formula (which do not use cells C7 or C6 in their calculation) are changed to NaN when re-read by a pandas dataframe. I needed to manually save in the Excel Application for a python df to read in the correct value again.

filename = 'Test_Data/test.xlsx'
workbook = load_workbook(filename=filename)
sheet = workbook.active
sheet["C7"] = 300
sheet["C6"] = 2356.19449
workbook.save(filename)
df = pd.read_excel(filename, header=None).loc[2:, [1,2,3]]
df.columns = ['a', 'b', 'c']
cell_value = df[3, 'a'] 

print(cell_value)

Unless I manually save in excel, this cell value is Nan. When i manually save, it returns to the cell value visible in the excel program.

0

There are 0 best solutions below