向日统计填入以下指定格式,1星级填入任意数字,宋体,左,上对齐;2星级将表格中已有文字改为隶书;# 3星级使表格中大于10的数字显示为红色
from xlutils.copy import copyimport xlrdimport xlwt
tem_excel = xlrd.open_workbook(‘D:/日统计.xls’, formatting_info=True)tem_sheet = tem_excel.sheet_by_index(0)
new_excel = copy(tem_excel)new_sheet = new_excel.get_sheet(0)
style = xlwt.XFStyle() # 初始化样式
font = xlwt.Font() # 设置字体font.name = '宋体’font.bold = Truefont.height = 360style.font = font # 将设置好的字体样式保存到新建的初始化样式中
borders = xlwt.Borders() # 设置边框borders.top = xlwt.Borders.THINborders.bottom = xlwt.Borders.THINborders.left = xlwt.Borders.THINborders.right = xlwt.Borders.THINstyle.borders = borders # 将设置好的边框样式保存到初始化样式中
alignment = xlwt.Alignment() # 设置对齐方式alignment.horz = xlwt.Alignment.HORZ_LEFTalignment.vert = xlwt.Alignment.VERT_TOPstyle.alignment = alignment # 将设置好的对齐方式