def _get_header_styles(self): s1 = XFStyle() al = Alignment() al.horz = Alignment.HORZ_CENTER s1.alignment = al s2 = XFStyle() borders = Borders() borders.bottom = 2 s2.borders = borders return s1, s2
def _get_header_style(self): # s1 = self._style_factory() al = Alignment() al.horz = Alignment.HORZ_CENTER # s1.alignment = al s2 = self._style_factory() borders = Borders() borders.bottom = 2 s2.borders = borders s2.alignment = al return s2
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(2).width = COL_WIDTH * 7 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
def add_ideogram_table(self, analyses, widths=None, # configure_table=True, add_title=False, add_header=False, tablenum=1, **kw): sh = self._wb.add_sheet(analyses[0].labnumber) # 'sheet{:02n}'.format(self._sheet_count)) self._sheet_count += 1 cols = ['Status', 'N', 'Power', 'Moles_40Ar', 'Ar40', 'Ar40Er', 'Ar39', 'Ar39Er', 'Ar38', 'Ar38Er', 'Ar37', 'Ar37Er', 'Ar36', 'Ar36Er', 'Blank', 'Ar40', 'Ar40Er', 'Ar39', 'Ar39Er', 'Ar38', 'Ar38Er', 'Ar37', 'Ar37Er', 'Ar36', 'Ar36Er' ] # write header row hrow = 0 borders = Borders() borders.bottom = 2 style = XFStyle() style.borders = borders for i, ci in enumerate(cols): sh.write(hrow, i, ci, style=style) numstyle = XFStyle() numstyle.num_format_str = '0.00' from operator import attrgetter def getnominal_value(attr): def get(x): v = getattr(x, attr) return float(v.nominal_value) return get def getstd_dev(attr): def get(x): v = getattr(x, attr) return float(v.std_dev) return get def getfloat(attr): def get(x): v = getattr(x, attr) return float(v) return get def null_value(): return lambda x: '' attrs = [(attrgetter('step'),), (getfloat('extract_value'),), (null_value(),), (getnominal_value('Ar40'),), (getstd_dev('Ar40'),), (getnominal_value('Ar39'),), (getstd_dev('Ar39'),), (getnominal_value('Ar38'),), (getstd_dev('Ar38'),), (getnominal_value('Ar37'),), (getstd_dev('Ar37'),), (getnominal_value('Ar36'),), (getstd_dev('Ar36'),), (null_value(),), (getnominal_value('Ar40_blank'),), (getstd_dev('Ar40_blank'),), (getnominal_value('Ar39_blank'),), (getstd_dev('Ar39_blank'),), (getnominal_value('Ar38_blank'),), (getstd_dev('Ar38_blank'),), (getnominal_value('Ar37_blank'),), (getstd_dev('Ar37_blank'),), (getnominal_value('Ar36_blank'),), (getstd_dev('Ar36_blank'),), ] for i, ai in enumerate(analyses): for j, arg in enumerate(attrs): if len(arg) == 2: func, style = arg else: func, style = arg[0], Style.default_style sh.write(i + hrow + 1, 1 + j, func(ai), style )