コード例 #1
0
ファイル: cpu_rate_log.py プロジェクト: CrzRabbit/PyTool
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
コード例 #2
0
ファイル: cpu_rate.py プロジェクト: CrzRabbit/PyTool
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
コード例 #3
0
 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
コード例 #4
0
    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="担当", style=style)
    workSheet.write(0, 1, label="commitSubject", style=style)
    workSheet.write(0, 2, label="commit time", style=style)
    workSheet.write(0, 3, label="branch", style=style)
コード例 #5
0
ファイル: demo3.py プロジェクト: caichang5201314/20201030
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)):
    sheet.write(4, i + 4, title[i], title_style)

content = [[1, 'SMITH', '测试', '蔡昶', '2020-10-10'],
コード例 #6
0
ファイル: views.py プロジェクト: sona201/bk_check_list
def template_download(request):
    """
    导出模板数据到excel
    """
    pk = request.GET.get('pk', '')
    business_name = request.GET.get('business_name', '')
    template_name = request.GET.get('template_name', '')
    flag = request.GET.get('flag', '')
    res_json = {'result': True, 'isNotPass': True, 'data': u""}
    if pk or flag == Flag.EDIT or flag == Flag.TASK or flag == 'False':
        business = BUSINESS_MODEL['template']
        cc_name = business_name
    elif flag == Flag.BUSINESS:
        business = BUSINESS_MODEL['instance']
        cc_name = business_name.split('_')[0]
    else:
        res_json['data'] = u'参数错误'
        return render_mako_context(request, '/manager/403.html', res_json)

    # 获取对应的模版并校验权限
    try:
        if pk:
            template = business.objects.get(id=pk)
            Application.objects.get(cc_name=template.business_name,
                                    operator__username=request.user.username)
        else:
            template = business.objects.get(business_name=business_name,
                                            template_name=template_name)
            Application.objects.get(cc_name=cc_name,
                                    operator__username=request.user.username)
    except ObjectDoesNotExist:
        res_json['data'] = u'您无操作权限,请联系系统管理员'
        return render_mako_context(request, '/manager/403.html', res_json)

    # 表格初始化
    response = HttpResponse(content_type="application/vnd.ms-excel")
    response['Content-Disposition'] = 'attachment; filename="%s_%s.xls"' % (
        template.business_name.encode('utf-8'),
        template.business_type.encode('utf-8'))
    wbk = xlwt.Workbook(encoding='utf-8')
    sheet = wbk.add_sheet('sheet1')
    sheet.col(2).width = 20000
    sheet.col(3).width = 20000

    # 枚举参数初始化
    if flag == Flag.EDIT or flag == Flag.TASK or flag == 'False':
        head_list = HeadList.TEMPLATE
        excel_list = ExcelList.TEMPLATE
        business_step = BUSINESS_STEP_MODEL["template"]
        business_detail = BUSINESS_DETAIL_MODEL['template']
        q = Q()
    else:
        q = ~Q(stat=1)
        head_list = HeadList.INSTANCE
        excel_list = ExcelList.INSTANCE
        business_step = BUSINESS_STEP_MODEL['instance']
        business_detail = BUSINESS_DETAIL_MODEL['instance']
    try:
        for i, data in enumerate(head_list):
            sheet.write(0, i, data)
        row = 1
        algn_center_hv = Alignment()
        algn_center_hv.horz = Alignment.HORZ_CENTER
        algn_center_hv.vert = Alignment.VERT_CENTER
        style_cdata = XFStyle()
        style_cdata.alignment = algn_center_hv

        # 获取步骤详情并填充表格
        steps = business_step.objects.filter(business=template).order_by('id')
        for step in steps:
            details = business_detail.objects.filter(
                q, business_step=step).order_by('step_xh')
            sheet.write_merge(row, row + details.count() - 1, 0, 0, step.name,
                              style_cdata)
            details = business_detail.to_dict(details)
            for detail in details:
                for i, value_key in enumerate(excel_list):
                    sheet.write(row, i + 1, detail[value_key])
                row += 1
        wbk.save(response)
        return response
    except Exception, e:
        logger.error(u'下载模版失败%s' % e)
        res_json['data'] = u'下载模版失败'
        return render_mako_context(request, '/manager/403.html', res_json)