2.用Python套用Excel模板,一鍵完成原亮樣式


from xlutils.copy import copy
import xlrd
import xlwt

tem_excel=xlrd.open_workbook('日統計.xls',formatting_info=True)

tem_sheet=tem_excel.sheet_by_index(0)

new_excel=copy(tem_excel)
new_sheet=new_excel.get_sheet(0)

'''
new_sheet.write(2,1,12)
new_sheet.write(3,1,18)
new_sheet.write(4,1,19)
new_sheet.write(5,1,15)
new_excel.save('填寫.xls')
'''

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('填寫2.xls')


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM