Python3比对两个表格


# get the list of files
'''
两个比对的文件夹,极其路径中名称不允许出现数字!!!
'''
import os
import openpyxl
import re
f_ls_1=os.listdir(r'E:\test-ex') # init list of files
f_ls_2=os.listdir(r'E:\test-af') # next list of files
# compare two list
if (f_ls_1==f_ls_2)==False:
    print('文件列表不同')
    os.system('pause')
else:
    pass

for f in f_ls_1:
    domin=os.path.abspath(r'E:\test-ex')# remember the f shall and loop shall came two different list
    e_f=os.path.join(domin,f) #complete file path
    wb=openpyxl.load_workbook(e_f) 
    sheet=wb['Worksheet']
    dl_pick=re.compile
    dl_pick=re.compile(r'\d{1,9}')
    dlid=dl_pick.search(e_f)
    dl_id_s=str('dlid')+str(dlid.group())

    row_max=sheet.max_row
    col_max=sheet.max_column
    ls_1=[dl_id_s]
    for row_num in range(2,row_max+1):
        for col_num in range(1,col_max+1):
            ls_1.append(sheet.cell(row=row_num,column=col_num).value)


    domin=os.path.abspath(r'E:\test-af')# remember the f shall and loop shall came two different list
    e_f=os.path.join(domin,f)
    wb=openpyxl.load_workbook(e_f)
    sheet=wb['Worksheet']
    dl_pick=re.compile
    dl_pick=re.compile(r'\d{1,9}')
    dlid=dl_pick.search(e_f)
    dl_id_s=str('dlid')+str(dlid.group())

    row_max=sheet.max_row
    col_max=sheet.max_column
    ls_2=[dl_id_s]
    for row_num in range(2,row_max+1):
        for col_num in range(1,col_max+1):
            ls_2.append(sheet.cell(row=row_num,column=col_num).value)
        result=(ls_1==ls_2)
    if result==False:
        print(dl_id_s,result)
    pass

工作中要比较两个文件夹中多个Excel表格是否相同


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM