先说下环境:
![](https://img-blog.csdnimg.cn/67090cbc225d477ba3032834851e2241.png)
Excel版本:![](https://img-blog.csdnimg.cn/bbaf90ac7abd4f5f9c4a65b6a0ddd748.png)
Python2.7.13和Python3.10.4并存。
![](https://img-blog.csdnimg.cn/484be2499fea486ea016488304ae7d29.png)
![](https://img-blog.csdnimg.cn/12cb57056a744da6b10c3c83d3b75909.png)
2、打开两个excel工作簿
![](https://img-blog.csdnimg.cn/b06fcbfc7b774978be2f30e5a90b0fe3.png)
看进程是这样的:
![](https://img-blog.csdnimg.cn/137b2793110544df8cac542a352c24e5.png)
![](https://img-blog.csdnimg.cn/f9172c9f28e7445ca6b9b1572c19136f.png)
![](https://img-blog.csdnimg.cn/01b2de08a380407b8b06e81aa62a3490.png)
3、用python编程kill进程
python"># -*- coding: utf-8 -*-
import os
proc_name='EXCEL.EXE'
if __name__ == '__main__':
os.system('taskkill /im {} /F'.format(proc_name))
运行即可关闭打开的所有Excel。
以上代码在python2和python3都可以。