如何使用 Python 启动应用程序实例? [英] How can I launch an instance of an application using Python?

查看:22
本文介绍了如何使用 Python 启动应用程序实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 Python 脚本,它执行一系列任务,其中一个任务是启动和打开 Excel 实例.在我的脚本中实现这一目标的理想方式是什么?

I am creating a Python script where it does a bunch of tasks and one of those tasks is to launch and open an instance of Excel. What is the ideal way of accomplishing that in my script?

推荐答案

虽然 Popen 的答案对于一般情况是合理的,但我会推荐 win32api 用于这种特定情况, 如果你想用它做一些有用的事情:

While the Popen answers are reasonable for the general case, I would recommend win32api for this specific case, if you want to do something useful with it:

事情是这样的:

from win32com.client import Dispatch
xl = Dispatch('Excel.Application')
wb = xl.Workbooks.Open('C:\Documents and Settings\GradeBook.xls')
xl.Visible = True    # optional: if you want to see the spreadsheet

取自邮件列表帖子,但是周围有很多例子.

Taken from a mailing list post but there are plenty of examples around.

这篇关于如何使用 Python 启动应用程序实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆