# ExcelReaders package: how to close an .xlsx file after opening it with: "openxl"?

**URL:** https://discourse.julialang.org/t/excelreaders-package-how-to-close-an-xlsx-file-after-opening-it-with-openxl/21180
**Category:** New to Julia
**Created:** [February 25, 2019, 5:03pm UTC](https://discourse.julialang.org/t/excelreaders-package-how-to-close-an-xlsx-file-after-opening-it-with-openxl/21180 "2019-02-25T17:03:27Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ale](https://avatars.discourse-cdn.com/v4/letter/a/f19dbf/32.png) [@ale](https://discourse.julialang.org/u/ale)
#### Post date: [February 25, 2019, 5:03pm UTC](https://discourse.julialang.org/t/excelreaders-package-how-to-close-an-xlsx-file-after-opening-it-with-openxl/21180/1 "2019-02-25T17:03:27Z")

</div>

Hello,

I am using `ExcelReaders` package to read several sheets from a very large .xlsx file.  
Thus, instead of repeating `foo_n = readxlsheet("data.xlsx", "sheetname_n")` for `n` times, it seemed to me to be more convenient and faster to use:

```julia
main_file = openxl("data.xlsx")
foo_1 = readxlsheet(main_file, "sheetname_1")
foo_2 = readxlsheet(main_file, "sheetname_2")
...

```

Which, if I got it right, keeps the whole large file `"data.xlsx"` in memory, so to permit a faster access whenever e.g. a new sheet needs to be read. Now I wonder: **is there a way to close such a large file once not needed anymore in the program**?  
I presume that by freeing up some memory, the latter could be used to run faster a very long script for instance.

Thank you in advance!

---

<div class="post-metadata">

### Author: ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)
#### Post date: [February 25, 2019, 6:54pm UTC](https://discourse.julialang.org/t/excelreaders-package-how-to-close-an-xlsx-file-after-opening-it-with-openxl/21180/2 "2019-02-25T18:54:21Z")

</div>

@davidanthoff would ` xlfile.workbook[:release_resources]()` make any difference, or is memory released through PyCall unavailable to Julia?

---

<div class="post-metadata">

### Author: ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)
#### Post date: [February 25, 2019, 7:43pm UTC](https://discourse.julialang.org/t/excelreaders-package-how-to-close-an-xlsx-file-after-opening-it-with-openxl/21180/3 "2019-02-25T19:43:54Z")

</div>

I think that would probably help! My understanding right now is that we actually load the entire content of an Excel file into memory on the Python side initially, and while we are holding onto that python object ([ExcelReaders.jl/ExcelReaders.jl at 301e68d7973cf611e86cab14a78fb65bf6e64c2f · queryverse/ExcelReaders.jl · GitHub](https://github.com/queryverse/ExcelReaders.jl/blob/301e68d7973cf611e86cab14a78fb65bf6e64c2f/src/ExcelReaders.jl#L23)) we are keeping that stuff in memory. I’m not sure how the PyCall story works on that end, but I assume that there might be a finalizer running for that `PyObject` that then reduces the ref count on the Python side? So essentially when the `main_file` var goes out of scope and is handled by the GC, it probably also frees the memory on the python side.

I think it might well be worth adding a method to `close` that accepts `main_file`, and that would trigger this closing earlier. @ale, do you want to open an issue on the repo? Thanks!

---

<div class="post-metadata">

### Author: ![felipenoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/felipenoris/32/553_2.png) [@felipenoris](https://discourse.julialang.org/u/felipenoris)
#### Post date: [February 25, 2019, 9:59pm UTC](https://discourse.julialang.org/t/excelreaders-package-how-to-close-an-xlsx-file-after-opening-it-with-openxl/21180/4 "2019-02-25T21:59:12Z")

</div>

Maybe you should give it a try and use `XLSX.jl`. There’s a specific mode for reading large files. See [https://felipenoris.github.io/XLSX.jl/latest/tutorial.html#Reading-Large-Excel-Files-and-Caching-1](https://felipenoris.github.io/XLSX.jl/latest/tutorial.html#Reading-Large-Excel-Files-and-Caching-1).

---

<div class="post-metadata">

### Author: ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)
#### Post date: [February 25, 2019, 10:11pm UTC](https://discourse.julialang.org/t/excelreaders-package-how-to-close-an-xlsx-file-after-opening-it-with-openxl/21180/5 "2019-02-25T22:11:05Z")

</div>

Yeah, I would second XLSX.jl! If you can avoid the Python dependency of ExcelReaders.jl you might also just generally have an easier time.
