Julia using openpyxl to change column width & row height

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:

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

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

ws.row_dimensions[1].height = 30 

Any hints?

1 Like

Hi have you fixed it?

Unfortunately no (last attempt with Julia 1.5.2)

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

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

I hope it helps :slight_smile:

1 Like

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

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

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

I had a similar problem with python-pptx, see python-pptx trouble · Issue #725 · JuliaPy/PyCall.jl · GitHub .