I am getting an error when setting the width of a column
workbook = Workbook()
#Add a sheet
worksheet = workbook.active
worksheet.column_dimensions["C"].width = 60.0
Here is the error.
KeyError: 'C'
There is no column "C" to resize.
Verify this with:
worksheet.columns
If you first create a cell in column C:
import openpyxl
wb = openpyxl.Workbook()
ws = wb.active
_cell = ws.cell(row=1, column=3)
You can then resize it, and not throw a KeyError:
ws.column_dimensions["C"].width = 60.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With