2016-12-29 62 views
2

如何使用python.net與office interop自動化Microsoft office? 我嘗試以下,但給錯誤:使用Python.Net自動化Microsoft word

import clr 
clr.AddReference("System") 
clr.AddReference("Microsoft.Office.Interop") 

from Microsoft.Office.Interop import Word 

wordApp = Word.Application() 
wordApp.Visible = True 
doc1 = wordApp.Documents.Add() 

AttributeError: '__ComObject' object has no attribute 'Add'

+0

在一箇舊的C#項目,我有'Word.Document DOC = wordApp.Documents.Add(Type.Missing,Type.Missing,Type.Missing,Type.Missing);' 。這四個參數在2010年左右的C#4.0中變得可選,這是爲了使COM調用更容易,例如, 'Word.Document doc = wordApp.Documents.Add();',但是這個特性在Python.NET中可能還不被支持。可能相關:http://stackoverflow.com/questions/26742837/creating-a-c-sharp-nullable-int32-within-python-using-python-net-to-call-a-c-s – Nat

回答