Trouble editing excel file using XLSX.jl package.

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:

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

1 Like

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

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:

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

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

Cheers.

You should write the code instead of posting screenshots

1 Like

I think this is error on openxlsx with PrinterSetting · Issue #71 · felipenoris/XLSX.jl · GitHub . I’ll debug this in a few days.

1 Like

That’s exactly it. Thanks a lot.

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

Can you check if it fixes your issue?

Cheers!

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

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

@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.

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.

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?

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.

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 …

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)")