我正在尝试更改 Excel 工作表中前两列的宽度,但我不断收到以下错误:wb.column_dimensions['A'].width = 25 AttributeError: 'Workbook' 对象没有属性 'column_dimensions'这是我的代码:from openpyxl import Workbookwb = Workbook()sheet = wb.activewb.column_dimensions['A'].width = 25wb.column_dimensions['B'].width = 25sheet["A1"] = "Date"sheet["B2"] = "Name"
1 回答
开满天机
TA贡献1786条经验 获得超13个赞
你需要sheet像这样解决:
from openpyxl import Workbook
wb = Workbook()
sheet = wb.active
sheet.column_dimensions['A'].width = 25
^
sheet.column_dimensions['B'].width = 25
^
sheet["A1"] = "Date"
sheet["B2"] = "Name"
添加回答
举报
0/150
提交
取消