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()