比对两个Excel 表格中使用列名与数字互换

#! python3
# -*- encoding: utf-8 -*-
'''
@File    :   fileread.py
@Time    :   2020/06/18 14:18:23
@Author  :   xuxiang 
@Version :   1.0
@Contact :   2998136503@qq.com
'''

import openpyxl
wb=openpyxl.load_workbook(r'-')#文件路径
wb_1=openpyxl.load_workbook(r'-')#文件路径
for name in wb.get_sheet_names():
    sheet=wb[name]
    sheet_1=wb_1[name]
    row_max=sheet.max_row
    col_max = sheet.max_column
    for row_i in range(1,row_max+1):
        for col_i in range(1,col_max+1):
            cell=sheet.cell(row=row_i,column=col_i).value
            cell_1=sheet_1.cell(row=row_i,column=col_i).value
            if cell==cell_1:
                pass
            else :
                print(name,row_i, openpyxl.utils.get_column_letter(col_i))
                input('>')
                pass

 Excel的列名与数字互换使用的是 openpyxl.utils模块中的

get_column_letter

column_index_from_string

 

posted @ 2020-06-18 14:24  余者皆可  阅读(196)  评论(0)    收藏  举报