from openpyxl import load_workbook
from openpyxl.styles import colors,PatternFill
import pandas as pd
def Read_Excel():
data1=pd.read_excel('1.xlsx',keep_default_na=False)
print(data1)
data2=pd.read_excel('2.xlsx',keep_default_na=False)
data1=data1.reset_index().astype('str')
data1.rename(columns={'index':'index1'},inplace=True)
data2=data2.reset_index().astype('str')
data2.rename(columns={'index':'index2'},inplace=True)
data3=data1.merge(data2,left_on='transaction_reference_number',right_on='交易日志号',how='outer')
print(data3)
data3.to_excel('3.xlsx')
return data3
def Fill_Color(in_filename,out_filename,index):
fill = PatternFill("solid", fgColor=colors.RED)
wb1=load_workbook(in_filename)
ws1=wb1['Sheet1']
con_max = ws1.max_column
for i in index:
for j in range(1,con_max+1):
ws1.cell(row=int(i)+2,column=j).fill=fill
wb1.save(out_filename)
data3=Read_Excel()
index_excel1=[]
index_excel2=[]
for i in data3.index:
if (data3.loc[i,'debit_amount'] !=data3.loc[i,'支出金额']) or (data3.loc[i,'credit_incurred_amount'] !=data3.loc[i,'收入金额'])\
or (data3.loc[i,'account_balance'] !=data3.loc[i,'本次余额']):
index_excel1.append(data3.loc[i,'index1'])
index_excel2.append(data3.loc[i,'index2'])
index_excel1=list(set(index_excel1))[1:]
index_excel2=list(set(index_excel2))[1:]
print(f'索引1:{index_excel1}')
print(f'索引2:{index_excel2}')
Fill_Color('1.xlsx','3.xlsx',index_excel1)
Fill_Color('2.xlsx','4.xlsx',index_excel2)
也不知道是不是你想要的,只能写成这样了 |