Saving XlsxWriter workbook more than once

I am writing software that manages Excel sheets. So far I have used xlrd and xlwt for this and everything works very well.

  • It opens a sheet (xlrd) and copies the selected columns into a new workbook (xlwt)
  • Then it opens the newly created data book (xlrd) and does some math and formatting with the data (which cannot be done if the file is not saved once) - (xlwt saves again)

However, now I am ready to add diagrams to my documents and this feature is not supported by xlwt. I found that xlsxwriter does this, but it adds other complications to my code: xlsxwriter only has one xlsxwriter.close()

that saves and closes the document.

Does anyone know if there is any workaround for this? Whenever I use xlsxwriter.close()

, my workbook object containing the document I am writing is no longer used.

+3


source to share


1 answer


There is essentially no reason why you need to read twice and save twice. For your current (no diagrams) process, you can simply read the data you want using xlrd; then do all your processing; and write once with xlwt.



After this workflow, it is pretty easy to replace xlwt with XlsxWriter.

+3


source







All Articles