python读写excel
xlutils
利用xlutils编辑已有excel,并维持原有样式
from xlutils.copy import copy as xlcopy
import xlrd
rb=xlrd.open_workbook(filepath,formatting_info=True)
wb=xlcopy(rb)
s=wb.get_sheet(sheetname)
for k,v in writedatas.items():
s.write(int(k),6,v)
s.write(int(k),8,'Y')
wb.save(filepath)
- 维持excel样式
xlutils的copy可以复制book的所有数据和样式,但是open_workbook默认是不带原有样式的,需要设置formatting_info=True
- get_sheet()

本文介绍如何使用Python的xlutils库编辑Excel文件的同时保持原有的表格样式。通过设置open_workbook的formatting_info参数为True来保留样式信息,并利用xlutils.copy进行数据更新。
1912

被折叠的 条评论
为什么被折叠?



