示例#1
0
 def add_image2(self,
                bmp_name='',
                x='',
                y='',
                length='',
                title_name='ceshi',
                sheet_name='sheet'):
     if sheet_name not in self.sheets:
         # Create if does not exist
         self.create_sheet(sheet_name)
     tall_style = xlwt.easyxf('font:height 820;')
     self.sheets[sheet_name]['sheet'].row(
         self.sheets[sheet_name]['rows']).set_style(tall_style)
     self.sheets[sheet_name]['sheet'].insert_bitmap('logo.bmp',\
                                                    x,y,0,0,scale_x=0.50,\
                                                    scale_y=0.60)
     if length:
         style = xlwt.XFStyle()  # Create Style
         font = xlwt.Font()
         font.bold = True
         font.height = 0x00FD
         style.font = font
         alignment = xlwt.Alignment()  # Create Alignment
         alignment.horz = xlwt.Alignment.HORZ_CENTER
         # May be: HORZ_GENERAL,HORZ_LEFT, HORZ_CENTER, HORZ_RIGHT, HORZ_FILLED, HORZ_JUSTIFIED,HORZ_CENTER_ACROSS_SEL, HORZ_DISTRIBUTED
         alignment.vert = xlwt.Alignment.VERT_CENTER
         # May be: VERT_TOP,VERT_CENTER, VERT_BOTTOM, VERT_JUSTIFIED, VERT_DISTRIBUTED
         style.alignment = alignment  # Add Alignment to Style
         self.sheets[sheet_name]['sheet'].write_merge(self.sheets[sheet_name]['rows'],self.sheets[sheet_name]['rows'],\
                                                     1,length-1,\
                                                     title_name,style)
     self.sheets[sheet_name]['rows'] += 1
示例#2
0
 def add_remark(self, remark_name, length, sheet_name='sheet'):
     if sheet_name not in self.sheets:
         # Create if does not exist
         self.create_sheet(sheet_name)
     style = xlwt.XFStyle()  # Create Style
     font = xlwt.Font()
     font.bold = False
     #font.height = 0x00EB
     font.height = 0x00FD
     style.font = font
     #style.alignment.wrap = xlwt.Alignment.WRAP_AT_RIGHT
     alignment = xlwt.Alignment()  # Create Alignment
     alignment.horz = xlwt.Alignment.HORZ_LEFT
     # May be: HORZ_GENERAL,HORZ_LEFT, HORZ_CENTER, HORZ_RIGHT, HORZ_FILLED, HORZ_JUSTIFIED,HORZ_CENTER_ACROSS_SEL, HORZ_DISTRIBUTED
     alignment.vert = xlwt.Alignment.VERT_CENTER
     # May be: VERT_TOP,VERT_CENTER, VERT_BOTTOM, VERT_JUSTIFIED, VERT_DISTRIBUTED
     alignment.wrap = xlwt.Alignment.WRAP_AT_RIGHT
     style.alignment = alignment  # Add Alignment to Style
     self.sheets[sheet_name]['sheet'].write_merge(self.sheets[sheet_name]['rows'],self.sheets[sheet_name]['rows'],\
                                                 0,length-1,\
                                                 remark_name,style)
     tall_style = xlwt.easyxf('font:height 820;')
     self.sheets[sheet_name]['sheet'].row(
         self.sheets[sheet_name]['rows']).set_style(tall_style)
     self.sheets[sheet_name]['rows'] += 1
示例#3
0
    def writerow(self, row, sheet_name='sheet', border=False, pattern_n=0):
        style = xlwt.XFStyle()
        if border:
            borders = xlwt.Borders()
            borders.left = 1
            borders.right = 1
            borders.top = 1
            borders.bottom = 1
            borders.bottom_colour = 0x3A

            style.borders = borders
        if pattern_n:
            pattern = xlwt.Pattern()  # Create the Pattern
            pattern.pattern = xlwt.Pattern.SOLID_PATTERN
            # May be: NO_PATTERN,SOLID_PATTERN, or 0x00 through 0x12
            pattern.pattern_fore_colour = pattern_n
            # May be: 8 through 63. 0 = Black, 1 = White, 2 = Red, 3 = Green, 4 = Blue,
            # 5 = Yellow, 6 = Magenta, 7 = Cyan, 16 = Maroon, 17 = Dark Green, 18 = Dark Blue, 19 = Dark Yellow ,
            # almost brown), 20 = Dark Magenta, 21 = Teal, 22 = Light Gray, 23
            # = Dark Gray,
            style.pattern = pattern  # Add Pattern to Style

        #sheet.write(0, 0, 'Firstname',style)
        if sheet_name not in self.sheets:
            # Create if does not exist
            self.create_sheet(sheet_name)

        if self.sheets[sheet_name]['rows'] == 0:
            self.sheets[sheet_name]['header'] = row

        if self.sheets[sheet_name]['rows'] >= 65534:
            self.save()
            # create new sheet to avoid being greater than 65535 lines
            self.create_sheet(sheet_name)
            if self.sheets[sheet_name]['header']:
                self.writerow(self.sheets[sheet_name]['header'], sheet_name)
        for ci, col in enumerate(row):
            if border:
                self.sheets[sheet_name]['sheet'].write(self.sheets[sheet_name]['rows'], ci,
                                                       self.cell(col) if not isinstance(
                                                           col, xlwt.ExcelFormula.Formula) else col,
                                                       style)
            else:
                self.sheets[sheet_name]['sheet'].write(self.sheets[sheet_name]['rows'], ci,
                                                       self.cell(col) if not isinstance(col, xlwt.ExcelFormula.Formula) else col)
            #print self.sheets[sheet_name]['rows'],ci, self.cell(col) if type(col) != lib.xlwt.ExcelFormula.Formula else col
        self.sheets[sheet_name]['rows'] += 1
示例#4
0
 def add_header(self, header_name, length, sheet_name='sheet'):
     if sheet_name not in self.sheets:
         # Create if does not exist
         self.create_sheet(sheet_name)
     style = xlwt.XFStyle()  # Create Style
     font = xlwt.Font()
     font.bold = True
     font.height = 0x00FB
     style.font = font
     alignment = xlwt.Alignment()  # Create Alignment
     alignment.horz = xlwt.Alignment.HORZ_CENTER
     # May be: HORZ_GENERAL,HORZ_LEFT, HORZ_CENTER, HORZ_RIGHT, HORZ_FILLED, HORZ_JUSTIFIED,HORZ_CENTER_ACROSS_SEL, HORZ_DISTRIBUTED
     alignment.vert = xlwt.Alignment.VERT_CENTER
     # May be: VERT_TOP,VERT_CENTER, VERT_BOTTOM, VERT_JUSTIFIED, VERT_DISTRIBUTED
     style.alignment = alignment  # Add Alignment to Style
     self.sheets[sheet_name]['sheet'].write_merge(self.sheets[sheet_name]['rows'],self.sheets[sheet_name]['rows'],\
                                                 0,length-1,\
                                                 header_name,style)
     self.sheets[sheet_name]['rows'] += 1
示例#5
0
    def write_title(self, sheet_name='sheet', border=False, pattern_n=0):
        style = xlwt.XFStyle()
        if border:
            borders = xlwt.Borders()
            borders.left = 1
            borders.right = 1
            borders.top = 1
            borders.bottom = 1
            borders.bottom_colour = 0x3A

            style.borders = borders
        if pattern_n:
            pattern = xlwt.Pattern()  # Create the Pattern
            pattern.pattern = xlwt.Pattern.SOLID_PATTERN
            # May be: NO_PATTERN,SOLID_PATTERN, or 0x00 through 0x12
            pattern.pattern_fore_colour = pattern_n
            # May be: 8 through 63. 0 = Black, 1 = White, 2 = Red, 3 = Green, 4 = Blue,
            # 5 = Yellow, 6 = Magenta, 7 = Cyan, 16 = Maroon, 17 = Dark Green, 18 = Dark Blue, 19 = Dark Yellow ,
            # almost brown), 20 = Dark Magenta, 21 = Teal, 22 = Light Gray, 23 = Dark Gray,
            alignment = xlwt.Alignment()  # Create Alignment
            alignment.horz = xlwt.Alignment.HORZ_CENTER
            # May be: HORZ_GENERAL,HORZ_LEFT, HORZ_CENTER, HORZ_RIGHT, HORZ_FILLED, HORZ_JUSTIFIED,HORZ_CENTER_ACROSS_SEL, HORZ_DISTRIBUTED
            alignment.vert = xlwt.Alignment.VERT_CENTER
            # May be: VERT_TOP,VERT_CENTER, VERT_BOTTOM, VERT_JUSTIFIED, VERT_DISTRIBUTED
            style.alignment = alignment  # Add Alignment to Style
            style.pattern = pattern  # Add Pattern to Style

        #sheet.write(0, 0, 'Firstname',style)
        if sheet_name not in self.sheets:
            # Create if does not exist
            self.create_sheet(sheet_name)

        if self.sheets[sheet_name]['rows'] == 0:
            self.sheets[sheet_name]['header'] = row

        if self.sheets[sheet_name]['rows'] >= 65534:
            self.save()
            # create new sheet to avoid being greater than 65535 lines
            self.create_sheet(sheet_name)
            if self.sheets[sheet_name]['header']:
                self.writerow(self.sheets[sheet_name]['header'], sheet_name)
        if border:
            self.sheets[sheet_name]['sheet'].write_merge(self.sheets[sheet_name]['rows'],\
                                                         self.sheets[sheet_name]['rows']+1,\
                                                         0,\
                                                         0,\
                                                         u"序号",\
                                                         style)
            self.sheets[sheet_name]['sheet'].write_merge(self.sheets[sheet_name]['rows'],\
                                                         self.sheets[sheet_name]['rows']+1,\
                                                         1,\
                                                         1,\
                                                         u"摘要",\
                                                         style)
            self.sheets[sheet_name]['sheet'].write_merge(self.sheets[sheet_name]['rows'],\
                                                         self.sheets[sheet_name]['rows']+1,\
                                                         2,\
                                                         2,\
                                                         u"资源名称",\
                                                         style)
            self.sheets[sheet_name]['sheet'].write_merge(self.sheets[sheet_name]['rows'],\
                                                         self.sheets[sheet_name]['rows']+1,\
                                                         3,\
                                                         3,\
                                                         u"端口",\
                                                         style)
            self.sheets[sheet_name]['sheet'].write_merge(self.sheets[sheet_name]['rows'],\
                                                         self.sheets[sheet_name]['rows']+1,\
                                                         4,\
                                                         4,\
                                                         u"speed",\
                                                         style)
            ### 接收速率(Mbps)
            self.sheets[sheet_name]['sheet'].write_merge(self.sheets[sheet_name]['rows'],\
                                                         self.sheets[sheet_name]['rows'],\
                                                         5,\
                                                         7,\
                                                         u"接收速率(Mbps)",\
                                                         style)
            self.sheets[sheet_name]['sheet'].write(self.sheets[sheet_name]['rows']+1,\
                                                         5,\
                                                         u"最大值",\
                                                         style)
            self.sheets[sheet_name]['sheet'].write(self.sheets[sheet_name]['rows']+1,\
                                                         6,\
                                                         u"平均值",\
                                                         style)
            self.sheets[sheet_name]['sheet'].write(self.sheets[sheet_name]['rows']+1,\
                                                         7,\
                                                         u"最小值",\
                                                         style)
            ### 接收利用率(%)
            self.sheets[sheet_name]['sheet'].write_merge(self.sheets[sheet_name]['rows'],\
                                                         self.sheets[sheet_name]['rows'],\
                                                         8,\
                                                         10,\
                                                         u"接收利用率(%)",\
                                                         style)
            self.sheets[sheet_name]['sheet'].write(self.sheets[sheet_name]['rows']+1,\
                                                         8,\
                                                         u"最大值",\
                                                         style)
            self.sheets[sheet_name]['sheet'].write(self.sheets[sheet_name]['rows']+1,\
                                                         9,\
                                                         u"平均值",\
                                                         style)
            self.sheets[sheet_name]['sheet'].write(self.sheets[sheet_name]['rows']+1,\
                                                         10,\
                                                         u"最小值",\
                                                         style)
            ### 发送速率(Mbps)
            self.sheets[sheet_name]['sheet'].write_merge(self.sheets[sheet_name]['rows'],\
                                                         self.sheets[sheet_name]['rows'],\
                                                         11,\
                                                         13,\
                                                         u"发送速率(Mbps)",\
                                                         style)
            self.sheets[sheet_name]['sheet'].write(self.sheets[sheet_name]['rows']+1,\
                                                         11,\
                                                         u"最大值",\
                                                         style)
            self.sheets[sheet_name]['sheet'].write(self.sheets[sheet_name]['rows']+1,\
                                                         12,\
                                                         u"平均值",\
                                                         style)
            self.sheets[sheet_name]['sheet'].write(self.sheets[sheet_name]['rows']+1,\
                                                         13,\
                                                         u"最小值",\
                                                         style)
            ### 发送利用率(%)
            self.sheets[sheet_name]['sheet'].write_merge(self.sheets[sheet_name]['rows'],\
                                                         self.sheets[sheet_name]['rows'],\
                                                         14,\
                                                         16,\
                                                         u"发送利用率(%)",\
                                                         style)
            self.sheets[sheet_name]['sheet'].write(self.sheets[sheet_name]['rows']+1,\
                                                         14,\
                                                         u"最大值",\
                                                         style)
            self.sheets[sheet_name]['sheet'].write(self.sheets[sheet_name]['rows']+1,\
                                                         15,\
                                                         u"平均值",\
                                                         style)
            self.sheets[sheet_name]['sheet'].write(self.sheets[sheet_name]['rows']+1,\
                                                         16,\
                                                         u"最小值",\
                                                         style)
            ### 带宽利用率
            self.sheets[sheet_name]['sheet'].write_merge(self.sheets[sheet_name]['rows'],\
                                                         self.sheets[sheet_name]['rows']+1,\
                                                         17,\
                                                         17,\
                                                         u"带宽利用率(%)",\
                                                         style)
            #print self.sheets[sheet_name]['rows'],ci, self.cell(col) if type(col) != lib.xlwt.ExcelFormula.Formula else col
        self.sheets[sheet_name]['rows'] += 2