使用pywin32,Dispatch和DispatchEx有什么区别?
打开时使用pywin32的电子表格,我发现有两种选择:
When opening e.g. a spreadsheet with pywin32, I found two options to do so:
excel1 = win32com.client.DispatchEx('Excel.Application')
wb = excel1.Workbooks.Open('myxls.xls')
或者我可以
excel2 = win32com.client.Dispatch('Excel.Application')
wb = excel2.Workbooks.Open('myxls.xls')
,我想知道这是否有区别.文档字符串也对我没有太大帮助:
and I'm wondering if this makes any difference. The docstrings don't help me much either:
>>> w32.Dispatch.__doc__
'Creates a Dispatch based COM object.\n '
>>> w32.DispatchEx.__doc__
'Creates a Dispatch based COM object on a specific machine.\n '
在此中他们建议DispatchEx
用于远程访问.
In this site they suggest that DispatchEx
might be for remote access.
当我只是尝试在自己的PC上自动执行电子表格时,使用哪种方法有什么区别?
Does it make any difference which method I use when I'm simply trying to automate spreadsheets on my own PC?
这取决于您想要的内容.如果Excel已打开,则使用dispatch将在打开的Excel实例中创建一个新选项卡.如果Excel已打开,则使用dispatchEx将打开Excel的新实例.
It depends on what you want. If Excel is already open, using dispatch will create a new tab in the open Excel instance. If Excel is already open, using dispatchEx will open a new instance of Excel.