# Reading in xlsx with multiple header rows using the XLSX Pkg

**URL:** https://discourse.julialang.org/t/reading-in-xlsx-with-multiple-header-rows-using-the-xlsx-pkg/61594
**Category:** General Usage
**Tags:** xlsx
**Created:** [May 21, 2021, 4:20pm UTC](https://discourse.julialang.org/t/reading-in-xlsx-with-multiple-header-rows-using-the-xlsx-pkg/61594 "2021-05-21T16:20:33Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![kbot](https://avatars.discourse-cdn.com/v4/letter/k/e9c0ed/32.png) [@kbot](https://discourse.julialang.org/u/kbot)
#### Post date: [May 21, 2021, 4:20pm UTC](https://discourse.julialang.org/t/reading-in-xlsx-with-multiple-header-rows-using-the-xlsx-pkg/61594/1 "2021-05-21T16:20:33Z")

</div>

I’m attempting to use [API Reference · XLSX.jl](https://felipenoris.github.io/XLSX.jl/stable/api/#XLSX.eachtablerow) to (called from a custom wrapper tool) to read in an excel workbook and create a dataframe.

However, the header is split across the top two rows → is there an alternative package/approach in Julia to specify the double header rows?

Thanks

---

<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 21, 2021, 7:54pm UTC](https://discourse.julialang.org/t/reading-in-xlsx-with-multiple-header-rows-using-the-xlsx-pkg/61594/2 "2021-05-21T19:54:55Z")

</div>

I don’t think there’s anything pre-built to handle this, but you should be able to pre-process the data to mangle the column headers together. As an example with this XLSX file

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

```julia
# f = path to file
julia> parse_dual(f)
4×4 DataFrame
 Row │ a.a a.b b.c b.d   
     │ Int64 Int64 Int64 Int64 
─────┼────────────────────────────
   1 │ 1 5 10 15
   2 │ 2 6 11 16
   3 │ 3 7 12 17
   4 │ 4 8 13 18

```

```julia
import XLSX
using DataFrames: DataFrame

function parse_dual(f, sheet=1)
    xf = XLSX.readxlsx(f)
    data = xf[sheet][:] # copy to matrix

    header = Symbol[]
    last_seen_row1 = nothing
    for (row1, row2) in zip(data[1, :], data[2, :])
        if !ismissing(row1)
            last_seen_row1 = row1
        end
        push!(header, Symbol(last_seen_row1, ".", row2))
    end

    columns = AbstractArray[]
    for col in eachcol(data[3:end, :])
        push!(columns, [x for x in col]) # comprehension reinfers type
    end
    return DataFrame(columns, header)
end

```

---

<div class="post-metadata">

### Author: ![kbot](https://avatars.discourse-cdn.com/v4/letter/k/e9c0ed/32.png) [@kbot](https://discourse.julialang.org/u/kbot)
#### Post date: [May 24, 2021, 8:46am UTC](https://discourse.julialang.org/t/reading-in-xlsx-with-multiple-header-rows-using-the-xlsx-pkg/61594/3 "2021-05-24T08:46:30Z")

</div>

Thanks Chris!
