Exemplo n.º 1
0
def writeToxls(file_name_xls, videos):
    head = Video.title_save()
    work_book = xlwt.Workbook(encoding='UTF-8')
    # 创建工作簿并命名
    sheet = work_book.add_sheet(sheetname='BiliBili-TOP100-NOW')
    data_list = []
    # 先写表头
    for i in range(len(head)):
        sheet.write(0, i, head[i])
    for i in videos:
        data_list.append(i.savedata())

    for z in range(len(head)):
        for j in range(len(videos)):
            sheet.write(j + 1, z, data_list[j][z])

    work_book.save(file_name_xls)
Exemplo n.º 2
0
def copy_excel(file_path,real_results,res_flags):  
    ''''' 
    :param file_path: 测试用例的路径 
    :param res_flags: 测试结果的list 
    :return: 
    '''  
    ''''' 
    这个函数的作用是写excel,把请求报文、返回报文和测试结果写到测试用例的excel中 
    因为xlrd模块只能读excel,不能写,所以用xlutils这个模块,但是python中没有一个模块能 
    直接操作已经写好的excel,所以只能用xlutils模块中的copy方法,copy一个新的excel,才能操作 
    '''  
    #打开原来的excel,获取到这个book对象  
    book = xlrd.open_workbook(file_path)  
    #复制一个new_book  
    new_book = copy.copy(book)  
    #然后获取到这个复制的excel的第一个sheet页  
    sheet = new_book.get_sheet(0)  
    i = 1
    for flag,real_result in zip(res_flags,real_results):  
        ''''' 
            同时遍历请求报文、返回报文和测试结果这3个大的list 
            然后把每一条case执行结果写到excel中,zip函数可以将多个list放在一起遍历 
            因为第一行是表头,所以从第二行开始写,也就是索引位1的位置,i代表行 
            所以i赋值为1,然后每写一条,然后i+1, i+=1同等于i=i+1 
            请求报文、返回报文、测试结果分别在excel的8、9、11列,列是固定的,所以就给写死了 
            后面跟上要写的值,因为excel用的是Unicode字符编码,所以前面带个u表示用Unicode编码 
            否则会有乱码 
        ''' 
        sheet.write(i,8,u'%s'%real_result) 
        sheet.write(i,9,u'%s'%flag) 
        i+=1     
        '''
                保存在excel的包下,p:当前路径的父包,
        os.path.join:进入当前路径的package
        format:
        '''
        p =os.path.abspath('..')
        excel_path=os.path.join(p, "Result")
        excel_path1=os.path.join(excel_path, "excel_result")
        print(excel_path1)    
        print('{}/{}_测试结果.xls'.format(excel_path1,time.strftime('%Y%m%d%H%M%S')))
        new_book.save('{}/{}_测试结果.xls'.format(excel_path1,time.strftime('%Y%m%d%H%M%S'))) 
Exemplo n.º 3
0
    def rewrite2sheet(self):
        "把?id *id重新写入sheet页"
        workbook = xlwt.Workbook(encoding='gbk')
        sheet: xlwt.Worksheet = workbook.add_sheet("qslist")
        for i in range(len(self.qsfieldName)):
            sheet.write(0, i, self.qsfieldName[i])
        r = 1
        for id in self.qslist:
            sheet.write(r, 0, id)
            sheet.write(r, 1, self.qslist[id])
            r += 1

        sheet: xlwt.Worksheet = workbook.add_sheet("rflist")
        for i in range(len(self.qsfieldName)):
            sheet.write(0, i, self.qsfieldName[i])
        r = 1
        for id in self.rflist:
            sheet.write(r, 0, id)
            sheet.write(r, 1, self.rflist[id])
            r += 1
        extpos = self.path.rfind(".")
        name = f"{self.path[0:extpos]}_qslist{self.path[extpos:]}"
        workbook.save(name)