Writing to xls file in Python

64 views Asked by At

I am having trouble writing to an existing XLS file in python. Here is what I have so far:

import_data = xlrd.open_workbook('Example.xls', on_demand=True)

Edit data, create work book, save new data to worksheet and then...

wb.save('Example.xls')

Error:

Invalid argument: 'Example.xls'

If I change the file name in the save method, it works exactly as intended. Example:

wb.save('Example2.xls')

So it would appear that I am having an issue writing to a file that already exists. I searched for a way to 'close' Example.xls but from what I read it sounds like that isn't necessary?

Thanks!

1

There are 1 answers

1
wrivas On

Try:

wb.release_resources()
# Edit your data.
wb.save('Example.xls')