标签:new font mat copy tin for utils from 输入数据
1 import xlrd 2 import xlwt 3 from xlutils.copy import copy 4 5 # 读取工作簿 6 objWB = xlrd.open_workbook(r‘C:\Users\IBM\Desktop\新建文件夹\S1-2\日统计.xls‘, formatting_info=True) 7 # 对象变量赋值 8 objSht = objWB.sheet_by_name(‘Sheet2‘) 9 # 复制工作簿 10 newWB = copy(objWB) 11 #获取第一个工作表 12 newSht = newWB.get_sheet(0) 13 #定义style y样式 14 Style = xlwt.XFStyle() 15 #定义Font 字体 16 Font = xlwt.Font() 17 Font.name = ‘微软雅黑‘ 18 Font.bold = True 19 Font.height = 18 * 20 20 Style.font = Font 21 #定义Borders 边框 22 Borders = xlwt.Borders() 23 Borders.top = xlwt.Borders.THIN 24 Borders.bottom = xlwt.Borders.THIN 25 Borders.left = xlwt.Borders.THIN 26 Borders.right = xlwt.Borders.THIN 27 Style.borders = Borders 28 #定义Alignment 对齐方式 29 Alignment = xlwt.Alignment() 30 Alignment.horz = xlwt.Alignment.HORZ_CENTER 31 Alignment.Vert = xlwt.Alignment.VERT_CENTER 32 Style.alignment = Alignment 33 #输入数据和相应Style 34 newSht.write(2, 1, 12, Style) 35 newSht.write(3, 1, 12, Style) 36 newSht.write(4, 1, 12, Style) 37 newSht.write(5, 1, 12, Style) 38 #保存 39 newWB.save(r‘C:\Users\IBM\Desktop\新建文件夹\S1-2\日统计1.xls‘)
标签:new font mat copy tin for utils from 输入数据
原文地址:https://www.cnblogs.com/Ionefox/p/10732478.html