# XLSX.jl: writing sheets from vectors

**URL:** https://discourse.julialang.org/t/xlsx-jl-writing-sheets-from-vectors/62007
**Category:** New to Julia
**Tags:** question, xlsx
**Created:** [May 28, 2021, 5:19pm UTC](https://discourse.julialang.org/t/xlsx-jl-writing-sheets-from-vectors/62007 "2021-05-28T17:19:27Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![PaulMainwood](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paulmainwood/32/9578_2.png) [@PaulMainwood](https://discourse.julialang.org/u/PaulMainwood)
#### Post date: [May 28, 2021, 5:19pm UTC](https://discourse.julialang.org/t/xlsx-jl-writing-sheets-from-vectors/62007/1 "2021-05-28T17:19:27Z")

</div>

In the package XLSX.jl, there is a useful capability of writing multiple excel sheets into a new file from several dataframes. From the documentation:

```julia
XLSX.writetable("report.xlsx", REPORT_A=( collect(DataFrames.eachcol(df1)), DataFrames.names(df1) ), REPORT_B=( collect(DataFrames.eachcol(df2)), DataFrames.names(df2) ))

```

If I have two vectors, one of sheet titles (i.e., report\_vec = [REPORT\_A, REPORT\_B, …]) , the other vector of DataFrames (i.e., df\_vec = [df1, df2, …]), each of length about 20, is it possible to write them all into the same excel file?

It feels as though I’m missing something very simple that involves splatting, but I just can’t get it. Any help very much appreciated.

---

<div class="post-metadata">

### Author: ![chris-b1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chris-b1/32/14165_2.png) [@chris-b1](https://discourse.julialang.org/u/chris-b1)
#### Post date: [May 28, 2021, 6:56pm UTC](https://discourse.julialang.org/t/xlsx-jl-writing-sheets-from-vectors/62007/2 "2021-05-28T18:56:18Z")

</div>

See below. It ends up a little complicated, building the NamedTuple, then splatting it into `writetable`

```julia
using DataFrames
import XLSX

report_vec = ["REPORT A", "REPORT B"]
dfs = [DataFrame(a=[1, 2, 3]), DataFrame(b=[4, 5, 6])]

nt = (;(Symbol(name) => (collect(eachcol(df)), names(df)) for (name, df) in zip(report_vec, dfs))...)
XLSX.writetable("test.xlsx"; nt...)

```
