0

I am trying to append multiple sheets from multiple excel. But a challenge I have is to skip the excel which not has that sheet name. here, Sheet name is variable..i.e softcode can be entered manually.

os.chdir(r'C:\Users')
files=os.listdir()
print("files read")
Sheet_count=int(input('No. of sheet to append: '))
sheet_list=[]
sheet_New=[]
for i in range(0,sheet_count):
    sheet_name=input('Enter the MO class to merge: ')
    sheet_list.append(sheet_name)
    sheet_New.append(sheet_name)
print(sheet_New)
for j in range(len(sheet_New)):
    sheet_New[j]=pd.DataFrame()
for f in files:
    for k in range(len(sheet_list)):
                df_temp = load_workbook(f, sheet_list[k])
                sheet_New[k] = sheet_New[k].append(df_temp)

the only challenge I have to skip the excel file which not has that sheet name

Light Yagami
  • 961
  • 1
  • 9
  • 29
MD SAJID
  • 106
  • 1
  • 8

0 Answers0