【Python办公】win32com打开Office、WPS文档的启动方式

1.说明

COM(Component Object Model)是一种面向组件的二进制接口标准,允许不同的软件模块之间进行交互和通信。Python中的win32com是使用Python控制com的公开库,对于操作软件非常方便,比如是操作Office软件进行文档自动化。Office和WPS都能控制,但是它们的启动方式确实不一样的

2.安装

pip install pywin32

3.Office启动项

# Office
from win32com import client

path = ''

app = client.Dispatch('Excel.Application')  # Excel
app.DisplayAlerts = False
wb = app.Workbooks.Open(path)

app = client.Dispatch('Word.Application')  # Word
app.DisplayAlerts = False
doc = app.Documents.Open(path)

app = client.Dispatch('PowerPoint.Application')  # PPT
app.DisplayAlerts = False
ppt = app.Presentations.Open(path)

4.WPS启动项

from win32com import client

path = ''

app = client.Dispatch("ket.Application")  # Excel
app.Visible = True
wb = app.WorkBooks.Open(path)

app = client.Dispatch("kwps.Application")  # Word
app.Visible = True
doc = app.Documents.Open(path)

app = client.Dispatch("kwpp.Application")  # PPT
app.Visible = True
ppt = app.Presentations.Open(path)

你可能感兴趣的:(python办公,python,wps,开发语言,Office,win32com,自动化)