|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import pandas as pd
from openpyxl import load_workbook
df = pd.DataFrame({'档案号':['0092018360733000001','0092018360733000005','0092018360733000008','0092018360733000011','0092018360733000012','0092018360733000015'],
'姓名':['肖健','糜修尘','兰希航','周杨子','李梦雯','陈领'],
'级别':['三级', '三级', '三级', '三级', '三级', '二级'],
'专业':['三级英语笔译', '三级英语笔译', '三级英语笔译', '三级英语笔译', '三级英语笔译', '二级英语笔译'],
'工作单位':['江西理工大学','自由职业','无','南昌大学','无','江西财经大学']})
writer = pd.ExcelWriter(r'D:\test\录取名单.xlsx')
df.to_excel(writer, '明细', index=0)
writer.save()
wb = load_workbook(filename = r'D:\test\录取名单.xlsx')
sht = wb["明细"]
sht.dimensions.ColumnDimension(bestFit=True)
wb.save(r'D:\test\录取名单.xlsx')
# 我希望实现自动调整列宽,代码执行过程中报错,请指教,谢谢。
# https://openpyxl.readthedocs.io/ ... eet.dimensions.html
# class openpyxl.worksheet.dimensions.ColumnDimension(worksheet, index='A', width=0, bestFit=False,
# hidden=False, outlineLevel=0, outline_level=None, collapsed=False, style=None, min=None, max=None,
# customWidth=False, visible=None, auto_size=None)[source] |
|