简体   繁体   English

如何在python上用pywinauto打开一个excel文件?

[英]How to open an excel file with pywinauto on python?

So Far, my code is:到目前为止,我的代码是:

from pywinauto import *
app = Application().start(r"C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\EXCEL.exe")
dlg = app.Excel
app = Application().connect(path=r"C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\EXCEL.exe")
dlg = app.Excel

But I can't Open a file!!但是我打不开文件!!

Any help would be apreciated!!任何帮助将不胜感激!!

PS I am using the gui so I can use an excel extension PS我正在使用gui所以我可以使用excel扩展

I open a file this way (don't forget to put "r" before both strings if you use single "\\")我以这种方式打开一个文件(如果您使用单个“\\”,请不要忘记将“r”放在两个字符串之前)

from pywinauto import Application

program_path = r"C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.exe"
file_path    = r"C:\file.xlsx"

app = Application().start(r'{} "{}"'.format(program_path, file_path))

If you just want to open an Excel program using Pywinauto, you can use this snippet codes as followed:如果您只想使用 Pywinauto 打开 Excel 程序,您可以使用以下代码片段:

from pywinauto import Application

app = Application(backend="uia")
app.start(r"C:/Program Files/Microsoft Office/root/Office16/EXCEL.exe")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM