Hello, I am encountering difficulties while trying to read a .xlsx file using Julia. Why is my code unable to find the sheet?
Difficult to know without taking a look at the Excel file
The error message says there is no sheet named “Sheet1”…
So maby try
fn = <filepath_to_xls>
df = DataFrame(XLSX.readtable(fn, "<nameofyoursheet>",infer_eltypes=true))
No, this is not an issue with the Excel file. I am certain that the sheet in my file is named “Sheet1”. I tested it with another file and found that it cannot recognize the sheet at all.
Looks like it could easily be a csv?
Unless this is part of some sort of pipeline where you’ll be working with similar Excel files going forward I would cut my losses, just save the file as csv, CSV.read
it and move on.
Not sure keys(workbook)
is the right way to access sheets. What does
XLSX.sheetnames(workbook)
return?
open
is not defined in XLSX.jl . It is a function in Base.
julia> XLSX.open === Base.open
true
You can find directions for reading an XLSX file in:
It could be an string encoding issue…
@nhz2 is right. You need nee to use one of the data getting functions in the XLSX.jl API. openxlsx
creates a workbook object, but if you only have one sheet, you might try readdata
or readtable
.
Your answer does help.Thanks! My code is partly writen by GPT. Maybe it’s not good at Julia.
I used 4o. I don’t think GPT is good at Julia.Maybe there is not enough data about Julia for GPT.\
qwen2.5-coder They claim better than 4o on Julia, worth trying as it’ s free.
While that is true, and explains the problem, why is that? It seems to me XLSX.open shouldn’t be defined, or even better should be XLSX.open === XLSX.readxlsx
(or just used instead). And maybe also XLSX.open === XLSX.openxlsx
.
@felipenoris, The first thing I see in the docs:
julia> import XLSX
julia> xf = XLSX.readxlsx("myfile.xlsx")
XLSXFile("myfile.xlsx") containing 3 Worksheets
It seems like a design mistake, it you want to prefix anyway, then why not just XLSX.open
and/or XLSX.read
? I’ve not looked into the difference, or what the even more obscure open_or_read_xlsx
does.
It doesn’t seem to late to add XLSX.open
as a synonym (for something, i.e. breaking XLSX.open === Base.open
that I doubt anyone relies upon).
I think openxlsx was chosen since then you could do something like
using XLSX: openxlsx
and use it unprefixed. But even then with as
you could have (by now) done:
using XLSX: open as openxlsx
I’m not sure we should be instructing people to use using
over import
anyway, or supporting the former better.
What qwen2.5-coder showed may actually work, I think we should allow what it shows (even if not fully consistent with the docs, I think it might work already) and whatever [Chat]GPT allows too!
@Dionysus since you’re new here, welcome, and the package should probably support load
already if it doesn’t, with:
If more and more file types are supported with FileIO, that interface, then it would help with AI guessing the right way to open. It’s good to know of it, and look there how to support new formats. But using the package alone is also perfectly fine.