Use Openpyxl to update cells in a file without saving the entire new workbook because it becomes corrupted upon loading

Question:

I am working on openpyxl code to check an excel file for human input errors and correct them. The code works fine for that purpose, but when I save it I cannot open the file because it becomes corrupted.

Upon using load_workbook() I get this error message:

"userwarning: conditional formatting extension is not supported and will be removed"

I can still read data and correct it within the workbook, but I cannot save it because that overwrites the file with a corrupted version that cannot open.

If I could simply write directly to the file without having to load the whole file as a workbook this would be one solution. I have no clue why the formatting extension is not supported in the first place but fixing that could be a second solution.

My openpyxl version is 3.0.4, changing the version I use is not really an option since I am working in an environment with restricted access.

Lastly, the excel file is .xlsm and I am trying to read from and write to that same file

Asked By: JLuka

||

Answers:

My solution for working with xlsm reading and writing is to use xlwings instead of pandas or openpyxl.

Answered By: JLuka
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.