import xlwings as xw #導入Xlwings module
import pandas as pd
app=xw.App(visible=True,add_book=False)
app.display_alerts=False #關閉Excel提示框
app.screen_updating=True #False 关闭屏幕更新,可加快宏的执行速度,看不見sheet內容
#檔案位置:filepath,打開檔案,保存,關閉,結束程式
filepath=r'C:\Users\test.xlsx'
wb=app.books.open(filepath)
a=wb.sheets['sheet1'].range('B2').value
b=wb.sheets['sheet2'].range('B2').value
c=wb.sheets['sheet1'].range('P2').value
d=wb.sheets['sheet2'].range('P2').value
e=wb.sheets['sheet2'].range('Q2').value
f=wb.sheets['sheet2'].range('V2').value
if a==b and d=="Passed":
wb.sheets['sheet1'].range('P2').value='Passed'
wb.sheets['sheet1'].range('Q2').value=e
wb.sheets['sheet1'].range('V2').value=f
if a==b and d=="Failed":
wb.sheets['sheet1'].range('P2').value='Failed'
wb.sheets['sheet1'].range('Q2').value=e
wb.sheets['sheet1'].range('V2').value=f
if a==b and d=="Blocked":
wb.sheets['sheet1'].range('P2').value='Blocked'
wb.sheets['sheet1'].range('Q2').value=e
wb.sheets['sheet1'].range('V2').value=f
if a==b and d=="Exempted":
wb.sheets['sheet1'].range('P2').value='Exempted'
wb.sheets['sheet1'].range('Q2').value=e
wb.sheets['sheet1'].range('V2').value=f
print(a,b,c,d,e,f)
#wb.save()
#wb.close()
#app.quit()