# Trying to improve code that provides simple Excel file writing functionality

**URL:** https://discourse.julialang.org/t/trying-to-improve-code-that-provides-simple-excel-file-writing-functionality/3259
**Category:** General Usage
**Created:** [April 18, 2017, 2:29am UTC](https://discourse.julialang.org/t/trying-to-improve-code-that-provides-simple-excel-file-writing-functionality/3259 "2017-04-18T02:29:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![askvorts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/askvorts/32/7120_2.png) [@askvorts](https://discourse.julialang.org/u/askvorts)
#### Post date: [April 18, 2017, 2:29am UTC](https://discourse.julialang.org/t/trying-to-improve-code-that-provides-simple-excel-file-writing-functionality/3259/1 "2017-04-18T02:29:20Z")

</div>

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

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [April 18, 2017, 2:42am UTC](https://discourse.julialang.org/t/trying-to-improve-code-that-provides-simple-excel-file-writing-functionality/3259/2 "2017-04-18T02:42:34Z")

</div>

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

---

<div class="post-metadata">

### Author: ![askvorts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/askvorts/32/7120_2.png) [@askvorts](https://discourse.julialang.org/u/askvorts)
#### Post date: [April 18, 2017, 3:02am UTC](https://discourse.julialang.org/t/trying-to-improve-code-that-provides-simple-excel-file-writing-functionality/3259/3 "2017-04-18T03:02:33Z")

</div>

> [@rdeits](#):
>
> `wb01[:close]()`

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!
