def create_xml(): workBook = xlwt.Workbook(encoding='utf-8') workSheet = workBook.add_sheet("record") workSheet1 = workBook.add_sheet("rate") workSheet.col(0).width = COL_WIDTH * 5 workSheet.col(1).width = COL_WIDTH * 5 workSheet.col(2).width = COL_WIDTH * 5 workSheet.col(3).width = COL_WIDTH * 5 workSheet.col(4).width = COL_WIDTH * 10 workSheet.row(0).height = ROW_HEIGHT * 4 workSheet1.col(0).width = COL_WIDTH * 8 workSheet1.col(1).width = COL_WIDTH * 8 workSheet1.col(2).width = COL_WIDTH * 8 workSheet1.col(3).width = COL_WIDTH * 8 font = xlwt.Font() font.bold = True font.colour_index = 0x09 style = xlwt.XFStyle() style.font = font style.pattern.pattern = style.pattern.SOLID_PATTERN #style.pattern.pattern_back_colour = 0x0C style.pattern.pattern_fore_colour = 0x08 borders = Borders() borders.left = Borders.MEDIUM borders.right = Borders.MEDIUM borders.top = Borders.MEDIUM borders.bottom = Borders.MEDIUM style.borders = borders aligment = Alignment() aligment.horz = Alignment.HORZ_CENTER aligment.vert = Alignment.VERT_CENTER style.alignment = aligment #style.alignment.wrap = Alignment.WRAP_AT_RIGHT content_font = xlwt.Font() content_style = xlwt.XFStyle() content_style.font = content_font content_style.alignment.horz = Alignment.HORZ_CENTER content_style.alignment.vert = Alignment.VERT_CENTER workSheet.write(0, 0, label="operation", style=style) workSheet.write(0, 1, label="id", style=style) workSheet.write(0, 2, label="channel", style=style) workSheet.write(0, 3, label="len", style=style) workSheet.write(0, 4, label="time", style=style) workSheet1.write(0, 0, label='operation', style=style) workSheet1.write(0, 1, label='start time', style=style) workSheet1.write(0, 2, label='end time(not include)', style=style) workSheet1.write(0, 3, label='package amount', style=style) workSheet1.write(0, 4, label='rate', style=style) return workBook, workSheet, workSheet1
def create_xml(): workBook = xlwt.Workbook(encoding='utf-8') workSheet = workBook.add_sheet("cpu_rate") workSheet.col(0).width = COL_WIDTH * 3 workSheet.col(1).width = COL_WIDTH * 3 workSheet.col(2).width = COL_WIDTH * 5 workSheet.col(3).width = COL_WIDTH * 5 workSheet.col(4).width = COL_WIDTH * 5 workSheet.col(5).width = COL_WIDTH * 5 workSheet.col(6).width = COL_WIDTH * 5 workSheet.col(7).width = COL_WIDTH * 5 workSheet.col(8).width = COL_WIDTH * 5 workSheet.row(0).height = ROW_HEIGHT * 4 font = xlwt.Font() font.bold = True font.colour_index = 0x09 style = xlwt.XFStyle() style.font = font style.pattern.pattern = style.pattern.SOLID_PATTERN #style.pattern.pattern_back_colour = 0x0C style.pattern.pattern_fore_colour = 0x08 borders = Borders() borders.left = Borders.MEDIUM borders.right = Borders.MEDIUM borders.top = Borders.MEDIUM borders.bottom = Borders.MEDIUM style.borders = borders aligment = Alignment() aligment.horz = Alignment.HORZ_CENTER aligment.vert = Alignment.VERT_CENTER style.alignment = aligment #style.alignment.wrap = Alignment.WRAP_AT_RIGHT content_font = xlwt.Font() content_style = xlwt.XFStyle() content_style.font = content_font content_style.alignment.horz = Alignment.HORZ_CENTER content_style.alignment.vert = Alignment.VERT_CENTER workSheet.write(0, 0, label="busy time", style=style) workSheet.write(0, 1, label="total time", style=style) workSheet.write(0, 2, label="totalCpuUsage", style=style) workSheet.write(0, 3, label="process name", style=style) workSheet.write(0, 4, label="thread name", style=style) workSheet.write(0, 5, label="pid/tid", style=style) workSheet.write(0, 6, label="user cpu", style=style) workSheet.write(0, 7, label="sys cpu", style=style) workSheet.write(0, 8, label="usage", style=style) return workBook, workSheet
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
#实际在这里开始for,循环的取excel中的动态值 if sheet_read_only.cell_value(6, 2) == 'form': content_type = 'application/x-www-form-urlencoded' else: content_type = 'application/json' #把取出的值进行转字典 params = eval(sheet_read_only.cell_value(6, 3)) response = request(request_type, url, params=params) rs = eval(response.text) # 仅仅获得所有的返回值 if response.status_code == sheet_read_only.cell_value( 6, 4) and rs['error_code'] == sheet_read_only.cell_value(6, 5): original_wb = open_workbook(r'd:\聚合数据.xls', formatting_info=True) new_wb = copy(original_wb) sheet = new_wb.get_sheet(0) border = Borders() border.left = border.THIN border.right = border.THIN border.top = border.THIN border.bottom = border.THIN style = XFStyle() style.borders = border sheet.write(6, 6, '通过', style) new_wb.save(r'd:\聚合数据测试报告.xls')
workSheet.col(3).width = COL_WIDTH * 6 workSheet.col(4).width = COL_WIDTH * 14 workSheet.col(5).width = COL_WIDTH * 6 workSheet.col(6).width = COL_WIDTH * 5 workSheet.row(0).height = ROW_HDEGHT * 4 font = xlwt.Font() font.bold = True font.colour_index = 0x09 style = xlwt.XFStyle() style.font = font style.pattern.pattern = style.pattern.SOLID_PATTERN #style.pattern.pattern_back_colour = 0x0C style.pattern.pattern_fore_colour = 0x08 borders = Borders() borders.left = Borders.MEDIUM borders.right = Borders.MEDIUM borders.top = Borders.MEDIUM borders.bottom = Borders.MEDIUM style.borders = borders aligment = Alignment() aligment.horz = Alignment.HORZ_CENTER aligment.vert = Alignment.VERT_CENTER style.alignment = aligment #style.alignment.wrap = Alignment.WRAP_AT_RIGHT content_font = xlwt.Font() content_style = xlwt.XFStyle() content_style.font = content_font content_style.alignment.horz = Alignment.HORZ_CENTER content_style.alignment.vert = Alignment.VERT_CENTER