def get_style(): fnt = Font() fnt.bold = True bor = Borders() bor.top = 1 bor.right = 1 bor.bottom = 1 bor.left = 1 al = Alignment() al.horz = Alignment.HORZ_CENTER al.vert = Alignment.VERT_CENTER style = XFStyle() style.font = fnt style.borders = bor style.alignment = al return style
from xlwt.Formatting import Borders, Font, Alignment, Pattern from xlwt.Style import XFStyle from xlwt.Workbook import Workbook wb = Workbook('utf-8') sheet = wb.add_sheet('测试报告') title = ['编号', '姓名', '职业', '上级', '入职日期'] title_style = XFStyle() border = Borders() border.left = border.THIN border.right = border.THIN border.top = border.THIN border.bottom = border.THIN font = Font() font.bold = True alignment = Alignment() alignment.horz = alignment.HORZ_CENTER pattern = Pattern() pattern.pattern = pattern.SOLID_PATTERN pattern.pattern_fore_colour = 0x35 title_style.borders = border title_style.font = font title_style.alignment = alignment title_style.pattern = pattern for i in range(len(title)):
from xlwt.Style import XFStyle from xlwt.Workbook import Workbook wb = Workbook('utf-8') sheet = wb.add_sheet('测试报告') sheet.write(1, 1, '自动化测试点') title = ['编号', '姓名', '职业', '上级', '入职日期'] title_style = XFStyle() border = Borders() border.left = border.THIN border.right = border.THIN border.top = border.THIN border.bottom = border.THIN font = Font() font.blod = True alignment = Alignment() alignment.horz = alignment.HORZ_CENTER pattern = Pattern() pattern.pattern = pattern.SOLID_PATTERN pattern.pattern_fore_colour = 0x35 title_style.borders = border title_style.font = font title_style.alignment = alignment title_style.pattern = pattern for i in range(len(title)):
def get_style_row(h): fnt = Font() fnt.height = h style = XFStyle() style.font = fnt return style