# Writing excel from dataframes

**URL:** https://discourse.julialang.org/t/writing-excel-from-dataframes/126932
**Category:** New to Julia
**Created:** [March 13, 2025, 7:38pm UTC](https://discourse.julialang.org/t/writing-excel-from-dataframes/126932 "2025-03-13T19:38:55Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![emt85](https://avatars.discourse-cdn.com/v4/letter/e/e47c2d/32.png) [@emt85](https://discourse.julialang.org/u/emt85)
#### Post date: [March 13, 2025, 7:38pm UTC](https://discourse.julialang.org/t/writing-excel-from-dataframes/126932/1 "2025-03-13T19:38:55Z")

</div>

Hi… I am somewhat new to julia and am still learning how to play around with data. I feel more comfortable with excel and want to export my dataframes into an excel sheet.

I followed this template:  
XLSX.writetable(  
“filename.xlsx”,  
sheet\_1 = (collect(eachcol(df1), names(df1))),  
sheet\_2 = (collect(eachcol(df2), names(df2))),  
)

I match it up to my previously set data frames but keep getting this error: ERROR: MethodError: no method matching collect(::DataFrames.DataFrameColumns{DataFrame}, ::Vector{String})

What should I do?

---

<div class="post-metadata">

### Author: ![eteppo](https://avatars.discourse-cdn.com/v4/letter/e/90db22/32.png) [@eteppo](https://discourse.julialang.org/u/eteppo)
#### Post date: [March 13, 2025, 8:00pm UTC](https://discourse.julialang.org/t/writing-excel-from-dataframes/126932/2 "2025-03-13T20:00:15Z")

</div>

Welcome! Looks like you have just a tiny typo there, use `collect(eachcol(df))` to make the vector of vectors. (Note the package seems to also allow input like `XLSX.writetable("filename.xlsx", "sheet_1" => df1, "sheet_2" => df2)`.)

---

<div class="post-metadata">

### Author: ![vzion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vzion/32/44768_2.png) [@vzion](https://discourse.julialang.org/u/vzion)
#### Post date: [March 14, 2025, 2:13pm UTC](https://discourse.julialang.org/t/writing-excel-from-dataframes/126932/3 "2025-03-14T14:13:45Z")

</div>

Another syntax you could use when you want to use space character in sheet name and column label metadata (instead of column name) :

```julia
 XLSX.writetable(
    "filename.xlsx", 
     var"df 1" = (eachcol(df1), labels(df1)),
     var"df 2" = (eachcol(df2), labels(df2))
 )

```

---

<div class="post-metadata">

### Author: ![emt85](https://avatars.discourse-cdn.com/v4/letter/e/e47c2d/32.png) [@emt85](https://discourse.julialang.org/u/emt85)
#### Post date: [March 17, 2025, 4:02pm UTC](https://discourse.julialang.org/t/writing-excel-from-dataframes/126932/4 "2025-03-17T16:02:37Z")

</div>

> [@eteppo](#):
>
> XLSX.writetable(“filename.xlsx”, “sheet\_1” =\> df1, “sheet\_2” =\> df2)

Thank you! This was helpful but now I received another error “Unsupported datatype Symbol for writing data to Excel file. Supported data types are Union{Missing, Bool, Float64, Int64, Date, DateTime, Time, String} or XLSX.CellValue.” Does this mean I need to change the data type of my data frame itself?

---

<div class="post-metadata">

### Author: ![TZ.Neumann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tz.neumann/32/34438_2.png) [@TZ.Neumann](https://discourse.julialang.org/u/TZ.Neumann)
#### Post date: [March 17, 2025, 5:16pm UTC](https://discourse.julialang.org/t/writing-excel-from-dataframes/126932/5 "2025-03-17T17:16:49Z")

</div>

Use in-place symbol to string conversion:

```julia
[df[!, col] .= string.(df[!, col]) for df in [df1, df2] for col in names(df) if eltype(df[!, col]) == Symbol]; 

XLSX.writetable("filename.xlsx", "sheet_1" => df1, "sheet_2" => df2)

```

---

<div class="post-metadata">

### Author: ![emt85](https://avatars.discourse-cdn.com/v4/letter/e/e47c2d/32.png) [@emt85](https://discourse.julialang.org/u/emt85)
#### Post date: [March 17, 2025, 5:53pm UTC](https://discourse.julialang.org/t/writing-excel-from-dataframes/126932/6 "2025-03-17T17:53:11Z")

</div>

Still getting the data type message ☹

---

<div class="post-metadata">

### Author: ![eteppo](https://avatars.discourse-cdn.com/v4/letter/e/90db22/32.png) [@eteppo](https://discourse.julialang.org/u/eteppo)
#### Post date: [March 17, 2025, 8:22pm UTC](https://discourse.julialang.org/t/writing-excel-from-dataframes/126932/7 "2025-03-17T20:22:19Z")

</div>

It’s always best to send a minimal working version of your troublesome code so that it can be copied, pasted, and run by others to help. In this case it looked like you have Symbol-typed columns in your DataFrames, and they need to be converted. Another clean way is by `using TidierData` package macros like `df1 = @mutate(df1, x = string(x), y = string(y))` where `x`, `y`, and so on are names of the symbol columns. You can tabulate the element types of each column neatly with `describe(df1, :eltype)`.

---

<div class="post-metadata">

### Author: ![TimG](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TimG](https://discourse.julialang.org/u/TimG)
#### Post date: [March 18, 2025, 12:17am UTC](https://discourse.julialang.org/t/writing-excel-from-dataframes/126932/8 "2025-03-18T00:17:31Z")

</div>

> “Unsupported datatype Symbol for writing data to Excel file. Supported data types are Union{Missing, Bool, Float64, Int64, Date, DateTime, Time, String} or XLSX.CellValue.”

This issue is captured in [#239](https://github.com/felipenoris/XLSX.jl/issues/239).

I have a fix ready to go, but am trying to resolve some other issues too. It may take a little while, but not too long, I hope!
