# Trouble editing excel file using XLSX.jl package.

**URL:** <https://discourse.julialang.org/t/trouble-editing-excel-file-using-xlsx-jl-package/20761>\
**Category:** New to Julia\
**Created:** [February 13, 2019, 6:52pm UTC](https://discourse.julialang.org/t/trouble-editing-excel-file-using-xlsx-jl-package/20761 "2019-02-13T18:52:36Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![rna1990](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rna1990/32/10797_2.png) [@rna1990](https://discourse.julialang.org/u/rna1990)\
**Post date:** [February 13, 2019, 6:52pm UTC](https://discourse.julialang.org/t/trouble-editing-excel-file-using-xlsx-jl-package/20761/1 "2019-02-13T18:52:36Z")

</div>

Greetings,

I’m writing code for a function whose output is an edited .xlsx file. I’m using package XLSX.jl for the purpose, but I’m getting the following error message:

 ![imagen](https://global.discourse-cdn.com/julialang/original/3X/3/8/3846886e0013f41c789057cbaffd58980bb4ec3b.png)

Thank you in advance for everyone’s help. Cheers.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [February 13, 2019, 7:16pm UTC](https://discourse.julialang.org/t/trouble-editing-excel-file-using-xlsx-jl-package/20761/2 "2019-02-13T19:16:03Z")

</div>

Can you post a minimum working example that reproduces the error?

---

<div class="post-metadata">

**Author:** ![rna1990](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rna1990/32/10797_2.png) [@rna1990](https://discourse.julialang.org/u/rna1990)\
**Post date:** [February 13, 2019, 7:50pm UTC](https://discourse.julialang.org/t/trouble-editing-excel-file-using-xlsx-jl-package/20761/3 "2019-02-13T19:50:16Z")

</div>

I think my problem has more to do with the usage of the function. Maybe a bug or something. I used the function just to read the file without doing anything to it and I got the same error message:

 ![imagen](https://global.discourse-cdn.com/julialang/original/3X/5/3/53d0bc48d29d1b44442c05787e5a74e7edf59539.png)

The line on the source code that appears to generate the problem is the following:

 ![imagen](https://global.discourse-cdn.com/julialang/original/3X/d/6/d6159ba230c32896b2b9bc11cda132c473f7efd1.png)

Sorry if my question is too vague or obscure, I’m new at Julia.

Cheers.

---

<div class="post-metadata">

**Author:** ![Juan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juan/32/7657_2.png) [@Juan](https://discourse.julialang.org/u/Juan)\
**Post date:** [February 14, 2019, 12:31am UTC](https://discourse.julialang.org/t/trouble-editing-excel-file-using-xlsx-jl-package/20761/4 "2019-02-14T00:31:43Z")

</div>

You should write the code instead of posting screenshots

---

<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 14, 2019, 4:52am UTC](https://discourse.julialang.org/t/trouble-editing-excel-file-using-xlsx-jl-package/20761/5 "2019-02-14T04:52:35Z")

</div>

I think this is [error on openxlsx with PrinterSetting · Issue #71 · felipenoris/XLSX.jl · GitHub](https://github.com/felipenoris/XLSX.jl/issues/71) . I’ll debug this in a few days.

---

<div class="post-metadata">

**Author:** ![rna1990](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rna1990/32/10797_2.png) [@rna1990](https://discourse.julialang.org/u/rna1990)\
**Post date:** [February 14, 2019, 2:35pm UTC](https://discourse.julialang.org/t/trouble-editing-excel-file-using-xlsx-jl-package/20761/6 "2019-02-14T14:35:51Z")

</div>

That’s exactly it. Thanks a lot.

---

<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 15, 2019, 1:51am UTC](https://discourse.julialang.org/t/trouble-editing-excel-file-using-xlsx-jl-package/20761/7 "2019-02-15T01:51:10Z")

</div>

@rna1990, I just merged a fix to branch `master`.

Can you check if it fixes your issue?

Cheers!

---

<div class="post-metadata">

**Author:** ![rna1990](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rna1990/32/10797_2.png) [@rna1990](https://discourse.julialang.org/u/rna1990)\
**Post date:** [February 15, 2019, 3:05am UTC](https://discourse.julialang.org/t/trouble-editing-excel-file-using-xlsx-jl-package/20761/8 "2019-02-15T03:05:24Z")

</div>

@felipenoris I tried again and now it throws an AssertionError :

 ![imagen](https://global.discourse-cdn.com/julialang/original/3X/3/0/30830218097fe1817c09f6b9d1239208b641b3ef.png)

---

<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 15, 2019, 3:15am UTC](https://discourse.julialang.org/t/trouble-editing-excel-file-using-xlsx-jl-package/20761/9 "2019-02-15T03:15:03Z")

</div>

I can’t tell what’s happening based on your print screen. Can you paste code?

---

<div class="post-metadata">

**Author:** ![rna1990](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rna1990/32/10797_2.png) [@rna1990](https://discourse.julialang.org/u/rna1990)\
**Post date:** [February 15, 2019, 7:02pm UTC](https://discourse.julialang.org/t/trouble-editing-excel-file-using-xlsx-jl-package/20761/10 "2019-02-15T19:02:57Z")

</div>

@felipenoris I can try later to paste some adapted code that replicates the error. I’m just trying to write some values calculated in Julia on an Excel template using XLSX.openxlsx(…, mode=“rw”) Meanwhile, from the error message I can understand that the function openxlsx uses a SheetRowIterator to read sheet content, but it returns nothing because of “@assert !isopen(state)” on line 122 of stream.jl

Thank you for trying to help me.

---

<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 16, 2019, 3:14pm UTC](https://discourse.julialang.org/t/trouble-editing-excel-file-using-xlsx-jl-package/20761/11 "2019-02-16T15:14:52Z")

</div>

I just tagged a new version for XLSX.jl. Use `Pkg.update()` to get the latest version. If your issue persists, try deleting your packages and install them again. If it still persists, let me know.

---

<div class="post-metadata">

**Author:** ![rna1990](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rna1990/32/10797_2.png) [@rna1990](https://discourse.julialang.org/u/rna1990)\
**Post date:** [February 18, 2019, 5:58pm UTC](https://discourse.julialang.org/t/trouble-editing-excel-file-using-xlsx-jl-package/20761/12 "2019-02-18T17:58:26Z")

</div>

Hello, Felipe.

I tried what you told me, but I’m still having the same problem. I also tried constructing a simplified version of my datasets, of my excel template and of the code I’m working on, but (sadly) I’m not able to reproduce the error message I’m getting (somehow, the writing I need to do on my excel template works just fine on the simplified version).

The error message I’m getting is because of the row iterator that openxlsx uses. It reads: “AssertionError: !(isopen(state))”. What does that mean? Is the function failing to close the xlsx file after editing, which causes an error or something like that?

---

<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 18, 2019, 7:27pm UTC](https://discourse.julialang.org/t/trouble-editing-excel-file-using-xlsx-jl-package/20761/13 "2019-02-18T19:27:58Z")

</div>

Sorry, I can’t do much to help you if I can’t reproduce the error.

Yes, you’re hitting an inconsistent state: the stream should be already closed when you’re at the last row of the worksheet. This might be a bug in the package XLSX.jl, or a malformed excel file.

I would be very interested to debug your case, since this is a core function in the whole package.

---

<div class="post-metadata">

**Author:** ![cwiese](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cwiese/32/4295_2.png) [@cwiese](https://discourse.julialang.org/u/cwiese)\
**Post date:** [October 18, 2019, 9:16pm UTC](https://discourse.julialang.org/t/trouble-editing-excel-file-using-xlsx-jl-package/20761/14 "2019-10-18T21:16:42Z")

</div>

I get this too on XLSX v0.5.7 ==\> LoadError: AssertionError: !(isopen(state))  
– if my XLSX.open\_xlsx\_template(file\_data\_path\*“/impact\_template.xlsx”) is clean new xlsx …it works… but if I add any thing like color to cells … open\_xlsx\_template fails …

---

<div class="post-metadata">

**Author:** ![cwiese](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cwiese/32/4295_2.png) [@cwiese](https://discourse.julialang.org/u/cwiese)\
**Post date:** [October 18, 2019, 9:18pm UTC](https://discourse.julialang.org/t/trouble-editing-excel-file-using-xlsx-jl-package/20761/15 "2019-10-18T21:18:11Z")

</div>

```julia
f = XLSX.open_xlsx_template(file_data_path*"/impact_template.xlsx")
    XLSX.writexlsx(log_path*"/$(file)_$(qry_req.id).xlsx", f; overwrite=true)
    XLSX.openxlsx(log_path*"/$(file)_$(qry_req.id).xlsx", mode="rw") do xf
        wb = XLSX.get_workbook(xf)
        numfmt = XLSX.styles_add_numFmt(wb, "_(* #,##0_);_(* (#,##0)")

```
