Reputation: 33
new to python and coding in general. I have a GUI that allows the user to browse to an excel file, open it, read it, and renames to a new directory. The process opens the excel file.
Two issues- 1. It takes a while for the excel file to open because of add-in's, etc. Is there a way to bypass the actual opening of the file? 2. The df.to_excel doesn't happen happen in the GUI until the opened excel file is manually closed.
Any help would be appreciated. Thanks!
import tkinter as tk
from tkinter import filedialog
import pandas as pd
import os
window = tk.Tk()
def openFile():
filename = filedialog.askopenfilename(initialdir = r'L:\My directory',
filetypes=[("Excel Files", "*.xlsx")])
os.system(filename)
df = pd.read_excel(filename, sheet_name = 'Order Details')
df.to_excel(r'C:/Users/Name/AppData/Local/Programs/Python/Project/DQ_File/scan.xlsx',index=False)
button = tk.Button(frame, text='Import Intelliscan File', bg='aliceblue', fg='black',command=openFile)
button.place(relx=0.03, rely=0.02, relheight=0.16, relwidth=0.95)
Upvotes: 0
Views: 1069
Reputation: 43495
The os.system
call blocks until the program it has started is finished. That is working as intended.
So that is why the conversion only happens after you close excel.
(If you want to open an excel file in excel without blocking, use subprocess.Popen
.)
If you just want to rename a file, use shutil.move
.
Upvotes: 1