Ifollowed this link to check how to open an excel file (open in a way similar to double cliking the file). How to open an Excel file with Python to display its content?
wnnmaw's answer works great but then i tried to improve it by using Stephan's answer since even wnnmaw says that Stephan's way is the way to go for only one file. Hower for some reasons, for me, the with part does not handle the closing of the workbook.my program continues after the end of the while but the file remains opened. Here is the most basic version of the code, but even this does not work.
with subprocess.Popen(["start", "/WAIT", retFle], shell=True) as doc:
#doc.poll()
bbg_df.to_excel(retFle, sheet_name ='Feuil1', )
sys.exit()
thanks for you help. I actually have to use excel that way because I am entering some forulas that will activate an excel add in that will pull some data. So I am waiting for this data, retrieve them and then I want to close the workbook.
EDIT:
Thanks to @Aran-Fey comments I arrived to this but it does not do the trick yet.
doc = subprocess.Popen(["start", "/WAIT", retFle], shell = True)
bbg_df.to_excel(retFle, sheet_name ='Feuil1', )
time.sleep(10)
for x in psutil.Process(doc.pid).children(recursive = True):
x.kill()
psutil.Process(doc.pid).kill()