# Read a .xlsx file

**URL:** <https://discourse.julialang.org/t/read-a-xlsx-file/122770>\
**Category:** General Usage\
**Tags:** question, xlsx\
**Created:** [November 18, 2024, 1:17pm UTC](https://discourse.julialang.org/t/read-a-xlsx-file/122770 "2024-11-18T13:17:35Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dionysus](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@Dionysus](https://discourse.julialang.org/u/Dionysus)\
**Post date:** [November 18, 2024, 1:17pm UTC](https://discourse.julialang.org/t/read-a-xlsx-file/122770/1 "2024-11-18T13:17:36Z")

</div>

Hello, I am encountering difficulties while trying to read a .xlsx file using Julia. Why is my code unable to find the sheet?

 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/f/ef6b76370733677d7566189a76c0b53425793542.png)

---

<div class="post-metadata">

**Author:** ![nandoconde](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nandoconde/32/19497_2.png) [@nandoconde](https://discourse.julialang.org/u/nandoconde)\
**Post date:** [November 18, 2024, 1:44pm UTC](https://discourse.julialang.org/t/read-a-xlsx-file/122770/2 "2024-11-18T13:44:31Z")

</div>

Difficult to know without taking a look at the Excel file 🙂

---

<div class="post-metadata">

**Author:** ![consumere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/consumere/32/209031_2.png) [@consumere](https://discourse.julialang.org/u/consumere)\
**Post date:** [November 18, 2024, 1:49pm UTC](https://discourse.julialang.org/t/read-a-xlsx-file/122770/3 "2024-11-18T13:49:05Z")

</div>

The error message says there is no sheet named “Sheet1”…  
So maby try

```julia
fn = <filepath_to_xls>
df = DataFrame(XLSX.readtable(fn, "<nameofyoursheet>",infer_eltypes=true))

```

---

<div class="post-metadata">

**Author:** ![Dionysus](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@Dionysus](https://discourse.julialang.org/u/Dionysus)\
**Post date:** [November 18, 2024, 2:16pm UTC](https://discourse.julialang.org/t/read-a-xlsx-file/122770/4 "2024-11-18T14:16:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dionysus](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@Dionysus](https://discourse.julialang.org/u/Dionysus)\
**Post date:** [November 18, 2024, 2:18pm UTC](https://discourse.julialang.org/t/read-a-xlsx-file/122770/5 "2024-11-18T14:18:18Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/0/5/05736bfc30e1757e60e711ed7417e4c71245174c.png)

---

<div class="post-metadata">

**Author:** ![Dionysus](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@Dionysus](https://discourse.julialang.org/u/Dionysus)\
**Post date:** [November 18, 2024, 2:19pm UTC](https://discourse.julialang.org/t/read-a-xlsx-file/122770/6 "2024-11-18T14:19:01Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/6/1/61e87135a3025586b15a5fc08dd821e801427169.png)  
this is my excel.

---

<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:** [November 18, 2024, 2:22pm UTC](https://discourse.julialang.org/t/read-a-xlsx-file/122770/7 "2024-11-18T14:22:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [November 18, 2024, 2:25pm UTC](https://discourse.julialang.org/t/read-a-xlsx-file/122770/8 "2024-11-18T14:25:01Z")

</div>

Not sure `keys(workbook)` is the right way to access sheets. What does

```julia
XLSX.sheetnames(workbook)

```

return?

---

<div class="post-metadata">

**Author:** ![nhz2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nhz2/32/44428_2.png) [@nhz2](https://discourse.julialang.org/u/nhz2)\
**Post date:** [November 18, 2024, 5:23pm UTC](https://discourse.julialang.org/t/read-a-xlsx-file/122770/9 "2024-11-18T17:23:09Z")

</div>

`open` is not defined in XLSX.jl . It is a function in Base.

```julia-repl
julia> XLSX.open === Base.open
true

```

You can find directions for reading an XLSX file in:

> **[Tutorial · XLSX.jl](https://felipenoris.github.io/XLSX.jl/stable/tutorial/#Tutorial)**
>
> Documentation for XLSX.jl.

---

<div class="post-metadata">

**Author:** ![consumere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/consumere/32/209031_2.png) [@consumere](https://discourse.julialang.org/u/consumere)\
**Post date:** [November 18, 2024, 5:25pm UTC](https://discourse.julialang.org/t/read-a-xlsx-file/122770/10 "2024-11-18T17:25:23Z")

</div>

It could be an string encoding issue…

---

<div class="post-metadata">

**Author:** ![mrufsvold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrufsvold/32/31600_2.png) [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)\
**Post date:** [November 18, 2024, 7:30pm UTC](https://discourse.julialang.org/t/read-a-xlsx-file/122770/11 "2024-11-18T19:30:41Z")

</div>

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

> **[API Reference · XLSX.jl](https://felipenoris.github.io/XLSX.jl/stable/api/#XLSX.openxlsx)**
>
> Documentation for XLSX.jl.

---

<div class="post-metadata">

**Author:** ![Dionysus](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@Dionysus](https://discourse.julialang.org/u/Dionysus)\
**Post date:** [November 19, 2024, 1:20am UTC](https://discourse.julialang.org/t/read-a-xlsx-file/122770/13 "2024-11-19T01:20:54Z")

</div>

Your answer does help.Thanks! My code is partly writen by GPT. Maybe it’s not good at Julia.

---

<div class="post-metadata">

**Author:** ![xgdgsc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xgdgsc/32/608_2.png) [@xgdgsc](https://discourse.julialang.org/u/xgdgsc)\
**Post date:** [November 19, 2024, 2:52am UTC](https://discourse.julialang.org/t/read-a-xlsx-file/122770/14 "2024-11-19T02:52:15Z")

</div>

Which GPT, just tried local ollama qwen2.5-coder

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/a/aab32162abad2bd09dcd5e47b9896d37e0c5d6e4.png)

---

<div class="post-metadata">

**Author:** ![Dionysus](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@Dionysus](https://discourse.julialang.org/u/Dionysus)\
**Post date:** [November 19, 2024, 2:59am UTC](https://discourse.julialang.org/t/read-a-xlsx-file/122770/15 "2024-11-19T02:59:31Z")

</div>

I used 4o. I don’t think GPT is good at Julia.Maybe there is not enough data about Julia for GPT.\

---

<div class="post-metadata">

**Author:** ![xgdgsc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xgdgsc/32/608_2.png) [@xgdgsc](https://discourse.julialang.org/u/xgdgsc)\
**Post date:** [November 19, 2024, 3:03am UTC](https://discourse.julialang.org/t/read-a-xlsx-file/122770/16 "2024-11-19T03:03:31Z")

</div>

[qwen2.5-coder](https://ollama.com/library/qwen2.5-coder) They claim better than 4o on Julia, worth trying as it’ s free.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [November 19, 2024, 4:54pm UTC](https://discourse.julialang.org/t/read-a-xlsx-file/122770/17 "2024-11-19T16:54:51Z")

</div>

> [@nhz2](#):
>
> `open` is not defined in [XLSX.jl](https://juliahub.com/ui/Packages/General/XLSX) . It is a function in Base.
> 
> ```julia
> julia> XLSX.open === Base.open
> true
> 
> ```

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

```julia
using XLSX: openxlsx

```

and use it unprefixed. But even then with `as` you could have (by now) done:

> **[Modules · The Julia Language](https://docs.julialang.org/en/v1/manual/modules/#Renaming-with-as)**
>
> Documentation for The Julia Language.

```julia
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.

> [@xgdgsc](#):
>
> Which GPT, just tried local ollama qwen2.5-coder

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:

> **[Home · FileIO](https://juliaio.github.io/FileIO.jl/stable/#Supported-formats)**
>
> Documentation for FileIO.

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.
