Dec-26-2019, 11:59 AM
(This post was last modified: Dec-26-2019, 12:06 PM by ashutoshdeodhar.)
Hi,
I am able to successfully preserve the formulas and also updating the required cells with desired values. Here is what I did.
exl = openpyxl.load_workbook(exlFile)
sheet = exl["Sheet1"]
now again define the same excel this time using data_only=true
exl1 = openpyxl.load_workbook(exlFile, data_only=True)
sheet1 = exl1["Sheet1"]
Now while reading the data from excel, use sheet1 while writing back to excel, use sheet in the same loop.
Also while saving the workbook at the end, use exl.save(exlFile) instead of exl1.save(exlFile)
With this I was able to retain all the formulas and also could update the required cells.
Let me know if this is sufficient or need more info
I am able to successfully preserve the formulas and also updating the required cells with desired values. Here is what I did.
exl = openpyxl.load_workbook(exlFile)
sheet = exl["Sheet1"]
now again define the same excel this time using data_only=true
exl1 = openpyxl.load_workbook(exlFile, data_only=True)
sheet1 = exl1["Sheet1"]
Now while reading the data from excel, use sheet1 while writing back to excel, use sheet in the same loop.
Also while saving the workbook at the end, use exl.save(exlFile) instead of exl1.save(exlFile)
With this I was able to retain all the formulas and also could update the required cells.
Let me know if this is sufficient or need more info