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()

  • 相关阅读:
    [常用的SQL语句总结]
    [HTML辅助方法Html.Raw()的简单应用]
    [抹零操作的三种方法]
    如何禁用ViewState,EnableViewState属性设置
    vs2008自定义代码段
    C#.net模拟提交表单GET、POST
    .net 判断对象属性,model对象属性是否赋值,PropertyInfo
    PHP的microtime()? 不!这是 asp.net版的microtime()
    很不错的验证码显示页
    GridView加入自动求和求平均值小计
  • 原文地址:https://www.cnblogs.com/setname/p/10531630.html
Copyright © 2011-2022 走看看