使用python关闭excel文件

使用python关闭excel文件,python,excel,Python,Excel,我想在打开excel文件后将其关闭。我搜索了这个网站,但找不到解决方案。有人能帮忙吗 import os #TODO: close the file 'myexcel.xlsx' before writing #writing data to 'myexcel.xlsx' here a = os.startfile('myexcel.xlsx')#open the file for reading 非常感谢。这不可能使用startfile()。根据文件: 启动关联的应用程序后,start

我想在打开excel文件后将其关闭。我搜索了这个网站,但找不到解决方案。有人能帮忙吗

import os

#TODO: close the file 'myexcel.xlsx' before writing

#writing data to 'myexcel.xlsx' here

a = os.startfile('myexcel.xlsx')#open the file for reading

非常感谢。

这不可能使用
startfile()
。根据文件:

启动关联的应用程序后,startfile()立即返回。没有等待应用程序关闭的选项,也无法检索应用程序的退出状态


您可以考虑使用该模块。根据您在这个问题上的具体操作,有大量的选项:

您想做什么取决于您想做什么,将其作为子进程启动并跟踪其进程ID对您来说可能更有趣。如果打开“myexcel.xlsx”,我们可以在Windows中终止进程吗?使用
startfile()
?我不这么认为——除非使用
taskkill
。也许这会有帮助?