Trying to improve code that provides simple Excel file writing functionality

The following code surprisingly allows writing to an Excel file (sometimes):

using PyCall, Compat
f = "myfile.xlsx"
vol = 0.15
@pyimport xlsxwriter.workbook as wb
wb01 = wb.Workbook(f)
worksheet = wb01[:add_worksheet]()
worksheet[:write](1,2,vol) # second row, third column

And myfile.xlsx cell C2 finally got 0.15. However the file is not saved yet, that only happens much later. Actually, when I quit Juno…Would it be possible to improve the code above so that Pycall could force saving the file immediately after the write command?

Note, in Windows 7:

  • REPL - Finishes running with code 0, there is no saved xlsx file
  • Juno - Finishes running with code 0, xlsx file is only saved after leaving Juno
  • Jupyter - Finishes running with code 0, there is no saved xlsx file

I think you just need to call wb01[:close]() whenever you’re done with that workbook to save and close it.

1 Like

Oh, I see. Thought that the file would always be saved after write, not needing to be closed first.Thank you very much!

Interesting to note that Juno, somehow, closes the file for us, allowing it to be saved before quitting. Well done!