P13xlutils写入Excel格式

from xlutils.copy import copy
import xlrd
import xlwt

tem_excel = xlrd.open_workbook(".\\files\\日统计.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 = True
font.height = 240   #字体是12号,要乘以20 ,设置为240

style.font = font

borders = xlwt.Borders()
borders.top = xlwt.Borders.THIN  #THIN是细线
borders.bottom = xlwt.Borders.THIN
borders.left = xlwt.Borders.THIN
borders.right = xlwt.Borders.THIN
style.borders = borders

alignment = xlwt.Alignment()
alignment.horz = xlwt.Alignment.HORZ_CENTER
alignment.vert = xlwt.Alignment.VERT_CENTER
style.alignment = alignment


new_sheet.write(2,1,12,style)
new_sheet.write(3,1,22,style)
new_sheet.write(4,1,32,style)
new_sheet.write(5,1,42,style)
new_excel.save(".\\output\\日统计填写.xls")

"""
注意:
1. 写入之前要人为设置格式
2. 一定要保存成xls格式,因为xlutils对office2003以后的版本支持很差
"""

你可能感兴趣的:(P13xlutils写入Excel格式)