# Julia using openpyxl to change column width & row height

**URL:** <https://discourse.julialang.org/t/julia-using-openpyxl-to-change-column-width-row-height/45172>\
**Category:** General Usage\
**Tags:** pycall\
**Created:** [August 18, 2020, 5:54pm UTC](https://discourse.julialang.org/t/julia-using-openpyxl-to-change-column-width-row-height/45172 "2020-08-18T17:54:08Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emmanouil\_Bakirtzis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/emmanouil_bakirtzis/32/11456_2.png) [@Emmanouil\_Bakirtzis](https://discourse.julialang.org/u/Emmanouil_Bakirtzis)\
**Post date:** [August 18, 2020, 5:54pm UTC](https://discourse.julialang.org/t/julia-using-openpyxl-to-change-column-width-row-height/45172/1 "2020-08-18T17:54:08Z")

</div>

Hi all,

I am using Julia 1.5.0 with openpyxl and I want to change the column width in an excel worksheet.

The python way to this is depicted here:  
[https://stackoverflow.com/questions/53906532/is-it-possible-to-change-the-column-width-using-openpyxl/53906585](https://stackoverflow.com/questions/53906532/is-it-possible-to-change-the-column-width-using-openpyxl/53906585)

However in Julia when I use openpyxl and try to do the same it does not work, because ws.column\_dimensions is an empty dictionary

```julia
using Conda
Conda.add("openpyxl")
using PyCall
xl = pyimport("openpyxl")

# create a workbook
wb = xl.Workbook()

# select active worksheet
ws = wb.active

# try to change the width of the column A --> NOT working
ws.column_dimensions["A"].width = 25

```

The same problem exists if I try to change the height of the first row using

```julia
ws.row_dimensions[1].height = 30 

```

Any hints?  
Thanks

---

<div class="post-metadata">

**Author:** ![ibabeo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ibabeo/32/9788_2.png) [@ibabeo](https://discourse.julialang.org/u/ibabeo)\
**Post date:** [November 17, 2020, 4:09pm UTC](https://discourse.julialang.org/t/julia-using-openpyxl-to-change-column-width-row-height/45172/2 "2020-11-17T16:09:04Z")

</div>

Hi have you fixed it?

---

<div class="post-metadata">

**Author:** ![Emmanouil\_Bakirtzis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/emmanouil_bakirtzis/32/11456_2.png) [@Emmanouil\_Bakirtzis](https://discourse.julialang.org/u/Emmanouil_Bakirtzis)\
**Post date:** [November 23, 2020, 8:33pm UTC](https://discourse.julialang.org/t/julia-using-openpyxl-to-change-column-width-row-height/45172/3 "2020-11-23T20:33:53Z")

</div>

Unfortunately no (last attempt with Julia 1.5.2)

---

<div class="post-metadata">

**Author:** ![raph](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@raph](https://discourse.julialang.org/u/raph)\
**Post date:** [January 8, 2021, 2:29pm UTC](https://discourse.julialang.org/t/julia-using-openpyxl-to-change-column-width-row-height/45172/4 "2021-01-08T14:29:21Z")

</div>

Hey 🙂 I had the same problem and I managed to solve it this way (for an existing .xlsx file):

```julia
from openpyxl.reader.excel import load_workbook
wb = load_workbook('output.xlsx')
sheet_ranges = wb['sheet1']
sheet_ranges.column_dimensions["A"].width = 40
wb.save('output.xlsx')

```

I hope it helps 🙂

---

<div class="post-metadata">

**Author:** ![Emmanouil\_Bakirtzis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/emmanouil_bakirtzis/32/11456_2.png) [@Emmanouil\_Bakirtzis](https://discourse.julialang.org/u/Emmanouil_Bakirtzis)\
**Post date:** [January 9, 2021, 1:45pm UTC](https://discourse.julialang.org/t/julia-using-openpyxl-to-change-column-width-row-height/45172/5 "2021-01-09T13:45:47Z")

</div>

@raph this is python, not julia… or am I missing something?

---

<div class="post-metadata">

**Author:** ![jaakkor2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jaakkor2/32/2540_2.png) [@jaakkor2](https://discourse.julialang.org/u/jaakkor2)\
**Post date:** [June 17, 2021, 6:14am UTC](https://discourse.julialang.org/t/julia-using-openpyxl-to-change-column-width-row-height/45172/6 "2021-06-17T06:14:30Z")

</div>

For some reason putting the width setting inside `py"""..."""` works.

```julia
using PyCall
xl = pyimport("openpyxl")
wb = xl.Workbook()
ws = wb.active
# ws.column_dimensions["A"].width = 25 ## ERROR: KeyError: key "A" not found
py"""
$ws.column_dimensions["A"].width = 25
"""
wb.save("foo.xlsx")

```

---

<div class="post-metadata">

**Author:** ![jaakkor2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jaakkor2/32/2540_2.png) [@jaakkor2](https://discourse.julialang.org/u/jaakkor2)\
**Post date:** [June 17, 2021, 6:23am UTC](https://discourse.julialang.org/t/julia-using-openpyxl-to-change-column-width-row-height/45172/7 "2021-06-17T06:23:51Z")

</div>

I had a similar problem with python-pptx, see [python-pptx trouble · Issue #725 · JuliaPy/PyCall.jl · GitHub](https://github.com/JuliaPy/PyCall.jl/issues/725) .

---

<div class="post-metadata">

**Author:** ![rashid.eee.edu](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@rashid.eee.edu](https://discourse.julialang.org/u/rashid.eee.edu)\
**Post date:** [November 23, 2023, 3:38pm UTC](https://discourse.julialang.org/t/julia-using-openpyxl-to-change-column-width-row-height/45172/8 "2023-11-23T15:38:36Z")

</div>

This post was temporarily hidden by the community for possibly being off-topic, unfocused, inappropriate, or spammy.

---

<div class="post-metadata">

**Author:** ![rashid.eee.edu](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@rashid.eee.edu](https://discourse.julialang.org/u/rashid.eee.edu)\
**Post date:** [November 23, 2023, 3:57pm UTC](https://discourse.julialang.org/t/julia-using-openpyxl-to-change-column-width-row-height/45172/9 "2023-11-23T15:57:21Z")

</div>

This post was temporarily hidden by the community for possibly being off-topic, unfocused, inappropriate, or spammy.
