美文网首页
xlutils套用Excel格式

xlutils套用Excel格式

作者: August________ | 来源:发表于2020-01-06 23:07 被阅读0次

    xlutils套用Excel格式

    • 总体流程思路
    37.png
    • 格式设置方式
    38.png
    • 脚本案例
    from xlutils.copy import copy
    import xlrd
    import xlwt
    
    tem_excel = xlrd.open_workbook(r'D:\python_work\1\CourseCode\Chapter1\S1-1-2\LessonCode\日统计.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_BOTTOM
    style.alignment = alignment
    
    new_sheet.write(2, 1, 12, style)
    new_sheet.write(3, 1, 15, style)
    new_sheet.write(4, 1, 19, style)
    new_sheet.write(5, 1, 11, style)
    new_excel.save(r'D:\python_work\excle\test12.xls')
    

    相关文章

      网友评论

          本文标题:xlutils套用Excel格式

          本文链接:https://www.haomeiwen.com/subject/nhplactx.html