设置列宽时出错
workbook = Workbook()
#Add a sheet
worksheet = workbook.active
worksheet.column_dimensions["C"].width = 60.0
这是错误。
KeyError: 'C'
最佳答案
。
用以下方法验证:
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)
然后可以调整大小,而不抛出KeyError:
ws.column_dimensions["C"].width = 60.0
关于python - 设置列宽时出现键错误-OpenPyXL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26955028/