Python win32com聚焦或打开Excel文件
我正在尝试使用win32com.client专注于Excel文件。
我想要的是:
(1)当已经打开给定的Excel文件时,只需返回工作簿实例即可。
(2)如果该Excel文件尚未打开>>打开Excel文件,然后返回工作簿实例。
我之所以挣扎,是因为我不知道方法getActiveObject和amp;派遣等...
在许多情况下,发生错误>> (-2147352567 .......
谁能制作我想要的代码?
这是我代码的一部分
'''
import win32com.client
xlsApp=win32com.client.GetActiveObject("Excel.Application")
myWB=xlsApp.Workbooks(workbook_name)
'''
i am trying to focus to excel file using win32com.client.
what i want is:
(1) simply return workbook instance when a given excel file is already opened.
(2) if that excel file is not opened yet >> open the excel file and then return workbook instance.
i am struggling because i don't know the difference between the methods getactiveobject & dispatch and so on...
in many cases, an error occurs >> (-2147352567 .......
can anyone make the code that i want?
this is a part of my code
'''
import win32com.client
xlsApp=win32com.client.GetActiveObject("Excel.Application")
myWB=xlsApp.Workbooks(workbook_name)
'''
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在此之前,我已经做到了,这是我这样做的方式,
需要您传递窗口标题,而不必是确切的名称,例如,如果您的Discord名为
Discord #general #general
您只是只有需要放置discord
,因为无论您去哪里discord
字符串都将始终在那里也存在,也将其打印
无许可
,因为某些应用程序需要它作为管理员运行I've done this before this is how I did it
That function requires you to pass in a window title, it does not have to be exact name for example if you have Discord named
Discord #general
you just need to putDiscord
because no matter where you goDiscord
string will always be in thereAlso the reason why it prints
No permission
because some applications requires it to run as Admin