Hi i made a python script to copy values from one excel file to another but now i need to prompt the user so that they can select the files from their file explorer without changing the path in the script itself what is the best way to do this ? the people that are going to work with it also don't really know alot about scripts what is the best dummy proof way to just let them run it ?
My code is the following:
import openpyxl as xl
from openpyxl.styles import Alignment, Font
# opening the source excel file
filename = "C:\\excelProjects\\Test Meg Vanhoef.xlsx"
wb1 = xl.load_workbook(filename)
ws1 = wb1.worksheets[0]`
# opening the destination excel file
filename1 = "C:\\excelProjects\\2223 Aanstipschema EGS v061221 - met koppeling forms.xlsx"
wb2 = xl.load_workbook(filename1)
ws2 = wb2.active
# calculate total number of rows in source excel file
mr = ws1.max_row
for i in range(2, mr+1):
#B
ws2['B{}'.format(i)] = ws1.cell(row=i, column=12).value
#C
ws2['C{}'.format(i)] = ws1.cell(row=i, column=13).value
#D
ws2['D{}'.format(i)] = ws1.cell(row=i, column=17).value
#E
ws2['E{}'.format(i)] = ws1.cell(row=i, column=15).value
#F
if ws1.cell(row=i, column=21).value == 'Andere':
ws2['F{}'.format(i)] = ws1.cell(row=i, column=22).value
else:
ws2['F{}'.format(i)] = ws1.cell(row=i, column=21).value
#G
Y_val = ws1.cell(row=i, column=25).value
Z_val = ws1.cell(row=i, column=26).value
ws2['G{}'.format(i)] = f"{Y_val} {Z_val}"
#H
ws2.cell(row=i, column=8).value = ws1.cell(row=i, column=27).value
#I
AG_val = ws1.cell(row=i, column=33).value
AB_val = ws1.cell(row=i, column=28).value
AC_val = ws1.cell(row=i, column=29).value
AN_val = ws1.cell(row=i, column=40).value
AH_val = ws1.cell(row=i, column=34).value
AJ_val = ws1.cell(row=i, column=36).value
ws2['I{}'.format(i)] = f"{AG_val} ({AB_val}, {AC_val}) \n{AN_val} ({AH_val}, {AJ_val})"
ws2['I{}'.format(i)].alignment = Alignment(wrapText=True)
#J
AF_val = ws1.cell(row=i, column=32).value
ws1.cell(row=i, column=39).font = Font(bold=True)
AM_val = ws1.cell(row=i, column=39).value
ws2['J{}'.format(i)] = f'{AF_val} ({AB_val}) \n{AM_val} ({AH_val})'
ws2['J{}'.format(i)].alignment = Alignment(wrapText=True)
#K
ws2['K{}'.format(i)] = ws1.cell(row=i, column=50).value
#L
ws2['L{}'.format(i)] = ws1.cell(row=i, column=51).value
#M
ws2['M{}'.format(i)] = ws1.cell(row=i, column=16).value
#N
ws2['N{}'.format(i)] = ws1.cell(row=i, column=41).value
#O
ws2['O{}'.format(i)] = ws1.cell(row=i, column=47).value
#P
ws2['P{}'.format(i)] = ws1.cell(row=i, column=49).value
#Q
ws2['Q{}'.format(i)] = ws1.cell(row=i, column=52).value
#S
BA_val = ws1.cell(row=i, column=53).value
BB_val = ws1.cell(row=i, column=54).value
CS_val = ws1.cell(row=i, column=96).value
CT_val = ws1.cell(row=i, column=97).value
if CS_val != 'Nederlands' and CT_val != 'Nederlands':
ws2['S{}'.format(i)] = f'{BA_val} \n{BB_val} \n\nTaal met moeder: {CS_val} \nTaal met vader: {CT_val}'
elif CT_val == 'Nederlands':
ws2['S{}'.format(i)] = f'{BA_val} \n{BB_val} \n\nTaal met vader: {CT_val}'
elif CS_val == 'Nederlands':
ws2['S{}'.format(i)] = f'{BA_val} \n{BB_val} \n\nTaal met moeder: {CS_val}'
else:
ws2['S{}'.format(i)] = f'{BA_val} \n{BB_val}'
ws2['S{}'.format(i)].alignment = Alignment(wrapText=True)
#W
BG_val = ws1.cell(row=i, column=59).value
BH_val = ws1.cell(row=i, column=60).value
BI_val = ws1.cell(row=i, column=61).value
BJ_val = ws1.cell(row=i, column=62).value
BK_val = ws1.cell(row=i, column=63).value
BL_val = ws1.cell(row=i, column=64).value
BM_val = ws1.cell(row=i, column=65).value
if BK_val == None and BM_val == None:
ws2['W{}'.format(i)] = f'{BG_val} \n{BH_val} \n{BI_val} \n{BJ_val} \n{BL_val}'
elif BM_val == None:
ws2['W{}'.format(i)] = f'{BG_val} \n{BH_val} \n{BI_val} \n{BJ_val} \nmedicatie: {BK_val} \n{BL_val}'
elif BK_val == None:
ws2['W{}'.format(i)] = f'{BG_val} \n{BH_val} \n{BI_val} \n{BJ_val} \n{BL_val} \nverwachtingen school: {BM_val}'
else:
ws2['W{}'.format(i)] = f'{BG_val} \n{BH_val} \n{BI_val} \n{BJ_val} \nmedicatie: {BK_val} \n{BL_val} \nverwachtingen school: {BM_val}'
ws2['W{}'.format(i)].alignment = Alignment(wrapText=True)
#AS
BO_val = ws1.cell(row=i, column=67).value
BP_val = ws1.cell(row=i, column=68).value
BR_val = ws1.cell(row=i, column=70).value
ws2['AS{}'.format(i)] = f'Hobby / talenten: {BO_val} / {BR_val} \nInteresses: {BP_val}'
ws2['AS{}'.format(i)].alignment = Alignment(wrapText=True)
#AU
BS_val = ws1.cell(row=i, column=71).value
BT_val = ws1.cell(row=i, column=72).value
BV_val = ws1.cell(row=i, column=74).value
BX_val = ws1.cell(row=i, column=76).value
BZ_val = ws1.cell(row=i, column=78).value
CB_val = ws1.cell(row=i, column=80).value
CD_val = ws1.cell(row=i, column=82).value
CE_val = ws1.cell(row=i, column=83).value
ws2['AU{}'.format(i)] = f'Talenten: {BS_val} / {BV_val} / {BT_val} \nLeermoeilijkheden: {BX_val} / {BZ_val} \nVroegere begeleiding: {CB_val} / {CD_val} \nBelemmerende factoren: {CE_val}'
ws2['AU{}'.format(i)].alignment = Alignment(wrapText=True)
#AW
CF_val = ws1.cell(row=i, column=84).value
AO_val = ws1.cell(row=i, column=41).value
CJ_val = ws1.cell(row=i, column=88).value
CL_val = ws1.cell(row=i, column=90).value
CN_val = ws1.cell(row=i, column=92).value
CO_val = ws1.cell(row=i, column=93).value
CP_val = ws1.cell(row=i, column=94).value
CQ_val = ws1.cell(row=i, column=95).value
if CO_val == 'ja':
ws2['AW{}'.format(i)] = f"Karakter: {CF_val} \nMedisch: {BG_val}, {BH_val}, {BL_val}, {BM_val} \nFamiliaal: {AO_val} \nMoeilijkheden: {CI_val} / {CK_val} \nVroegere ondersteuning: {CM_val} / {CO_val} \nBelemmerende factoren: Indien \npestverleden \n{CQ_val} {CR_val}"
else:
ws2['AW{}'.format(i)] = f"Karakter: {CF_val} \nMedisch: {BG_val}, {BH_val}, {BL_val}, {BM_val} \nFamiliaal: {AO_val} \nMoeilijkheden: {CI_val} / {CK_val} \nVroegere ondersteuning: {CM_val} / {CO_val} \nBelemmerende factoren: Indien \n{CQ_val} {CR_val}"
ws2['AW{}'.format(i)].alignment = Alignment(wrapText=True)
# saving the destination excel file
wb2.save(str(filename1))