Reputation: 335
In Visual studio there is an option to register as an Interop COM. I want to achieve the same using python language. If someone can help me how to go about this. I did my research but couldnt find anything.
Upvotes: 1
Views: 5144
Reputation: 335
import win32com.server.register
win32com.server.register.UseCommandLine(ClassName)
Upvotes: 0
Reputation: 4434
Like my namesake comments above. Use the pywin32 module. Alternatively you can use the comtypes module instead. Because python is a interpreted language you can use COM in 2 separate ways. By generating a interoperability layer or by dynamic typing. Both comtypes and pywin32, can do dynamic typing. Additionally pywin32's win32com module can also generate a interoperability layer, this has a drawback tough as dynamic typing is often easier to handle. Here is a simple example that generates a interop like compatibility layer (if on does not exist) in excel. Then the script opens a existing worksheet and edits the first cell value:
from win32com.client.gencache import EnsureDispatch
xl = EnsureDispatch ("Excel.Application")
xl.Visible = True
wb = xl.Workbooks.Open(r'c:\temp\test.xlsx')
sht = wb.Worksheets(1)
sht.Cells(1,1).Value = "yeah this works"
PS: Stack overflow already automatically suggests a lot of resources for you to follow in the related sidebar.
Upvotes: 1