「編程」python自動辦公——自動設置excel表格樣式

給excel設置漂亮樣式

from xlutils.copy import copy 
import xlrd
import xlwt

tem_excel=x1rd.open_workbook("D:/temp.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=360
style.font=font
//邊框
borders =xlwt.Borders()
borders.top=xlwt.Borders.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,18,style)
new_sheet.write(4,1,19,style)
new_sheet.write(5,1,15,style)
new_excel.save(D:/填寫.xls)
「編程」python自動辦公——自動設置excel表格樣式


分享到:


相關文章: