zoukankan      html  css  js  c++  java
  • 使用python读写操作excel内两个不同表(基于python3.6)

    #!/usr/bin/python3
    # -*- coding: utf-8 -*-
    # @File    : csvHandle
    # @Author  : moucong
    # @Date    : 2019/3/14 15:28
    # @Software: PyCharm

    import openpyxl


    def csv_handle():
        filename = "all.xlsx"
        wb = openpyxl.load_workbook(filename)
        sheets = wb.sheetnames    #拿到表名
        sheet_prize = wb[sheets[0]]  #拿到组内的表名
        sheet_visitor = wb[sheets[1]]
        for r in range(1, sheet_prize.max_row + 1):
            prize_value = str(sheet_prize.cell(row=r, column=2).value)
            # print(str(sheet_prize.cell(row=r, column=2).value))
            for i in range(1, sheet_visitor.max_row + 1):
                vistor_value = sheet_visitor.cell(row=i, column=1).value
                if vistor_value == prize_value:
                    print(str(vistor_value) + "匹配成功!")
                    mobile = str(sheet_visitor.cell(row=i, column=19).value)   #可将某值调出查看,row'行',column'列'
                    company = str(sheet_visitor.cell(row=i, column=6).value)
                    jobTitle = str(sheet_visitor.cell(row=i, column=7).value)
                    line_company = 'I' + str(r)
                    line_mobile = 'J' + str(r)
                    line_jobTitle = 'K' + str(r)
                    sheet_prize[line_mobile] = mobile       #直接赋值给表中的J列r行
                    sheet_prize[line_company] = company
                    sheet_prize[line_jobTitle] = jobTitle
                    print(sheet_prize[line_mobile].value)
                    break
                else:
                    print(str(prize_value) + '' + "没有该用户 ")
                    continue
        print('完成匹配,正在保存!')
        wb.save(filename=filename)   #记住一定要保存


    if __name__ == '__main__':
        csv_handle()

  • 相关阅读:
    如何判断某个变量是否是数组?
    mac vscode编辑器的快捷键
    vue require.context()动态文件引入
    在vue项目上使用less
    nrm是什么
    对象的扩展方法
    es5严格模式
    微信公众号定位不准问题
    layer使用iframe的路径不对问题
    form表单中reset对js赋值的表单象无法重置问题
  • 原文地址:https://www.cnblogs.com/setname/p/10531630.html
Copyright © 2011-2022 走看看