from tkinter import filedialog from tkinter import Tk from tkinter import * root = Tk() root.input = filedialog.askopenfilename(filetypes=((".xlsx", "*.xlsx"), ("All files", "*.*")), title="Open input data table") root.withdraw() folder_EnergyPLAN = filedialog.askdirectory(title="Open EnergyPLAN folder") '-----------------------------------------' import os # Gives user's home directory userhome = os.path.expanduser('~') print("User's home Dir: " + userhome) import subprocess POWERSHELL_COMMAND = r'C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe' subprocess.Popen([POWERSHELL_COMMAND, 'dir {}\Downloads\qres -Recurse | Unblock-File'.format(userhome)], stdout=subprocess.PIPE, stderr=subprocess.PIPE) '--------------------define input file----------------------------' import openpyxl path = ((root.input)) wb_obj = openpyxl.load_workbook(path) sheet_obj = wb_obj.active m_row = sheet_obj.max_row m_col = sheet_obj.max_column '-------------------define file storage location-------------------------------' for j in range(1, m_col+1): name = sheet_obj.cell(row=2200, column=j).value outputFile = open(r'{0}\energyPlan Data\Data\{1}.txt'.format(folder_EnergyPLAN, name), 'w') for i in range(1, m_row + 1): cell_obj = sheet_obj.cell(row=i, column=j) print(cell_obj.value, file=outputFile) outputFile.close()