简体   繁体   中英

How do you open an excel file and then click a dialog box before reading the file, from a python script?

I get these excel files at work sent to me that I am trying to read from python to automate. The problem is that the full contents of the file are not loaded from simply opening the file. Once you open the file there is a dialog box that pops up where I can click "Show Content" and then all the content will load.

I need some way from python to open the excel file, click this button, and then read the contents. Is this possible? I have the code to simply create a tkinter gui prompt to upload a file and to then read from that file with openpyxl. I just need a way to open the file, then click the button.

Edit: Also closing the Excel prompt will allow the content to load, so I can either click the button on the prompt or close the prompt, but I need to do this with python, then wait, then read the sheets.

from openpyxl.workbook import Workbook
from openpyxl import load_workbook
from tkinter import *
from tkinter.filedialog import askopenfile

root = Tk()
root.geometry("300x300")

def open_file():
    file = askopenfile(mode='r', filetypes = [('Excel Files', '*.xlsx *.xlsm *.csv')])
    wb = load_workbook(filename = file.name)
    root.destroy()
    pass
    # I will write code to check for certain values in the file and match here

btn = Button(root, text='Open', command = open_file)
btn.pack(side='top')

mainloop()

I was able to read and write to the file without opening it, this bypassed the error I was receiving.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM