• 使用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()

  • 相关阅读:
    Control Group(CGroup)资源限制组
    系统安全之用户认证
    如何在Linux中禁用和挂起休眠
    ubuntu18 virtualbox启动失败Kernel driver not installed (rc=-1908)
    C# Winform 多线程更新界面UI控件,解决界面卡顿问题(转)
    【573】LaTeX相关技巧
    程序计时函数
    王炸!!Spring 终于对 JVM 动手了…
    ThreadLocalRandom 是线程安全的吗?
    Spring Boot 应用可视化监控,一目了然!
  • 原文地址:https://www.cnblogs.com/setname/p/10531630.html
Copyright © 2020-2023  润新知