[IronPython] Urgent : Unable to open MS Word file from Python
Sivaguru Perambalam
itssivaguru at gmail.com
Wed Jun 3 22:35:42 CEST 2009
Hello,
I have written this small script, which is (part of an application that is)
supposed to open a MS Word Document and manipulate it (do a search and
replace) .
I am getting a weird exception when I try to run the script.
It says TypeError: expected clr.Reference, got str for the line where I try
to open the file.
But the same script runs fine on a colleague's computer .
I couldn't figure out what his computer has that mine doesn't.So I thought
of asking what are the necessary things (libs, dlls) that are needed to
Open/Work on MS Word File from Iron Python.
MS Excel interaction works fine in my computer though. I have Office 07, MS
Visual Studio 05, .NET Framework 2.0 installed in my computer. I have also
verified that Microsoft.Office.Interop.Word version 12.0.0.0 is found
registered in the Assembly Cache.
This issue has become a Show-stopper for the Application I am working on.
So, any helpful suggestions or directions would mean a lot !
Thanks !!
Script :
import clr
import System
clr.AddReference("Microsoft.Office.Interop.Word")
import Microsoft.Office.Interop.Word as Word
source_filename = 'C:\Sample_Report.doc'
destination_filename = 'c:\Validation Report.doc'
missing = System.Type.Missing
replaceAll = Word.WdReplace.wdReplaceAll
# Open the Report Template MSWord File
word_application = Word.ApplicationClass()
word_application.Visible = False
document = word_application.Documents.Open(source_filename)
print 'opened microsoft word'
document.SaveAs(destination_filename)
document.Close()
document = None
word_application.Quit()
word_application = None
Error Message :
> "C:\Program Files\DotQuestLite\Bin\ipy.exe" word.py
Traceback (most recent call last):
File C:\Documents and Settings\sp19206\Desktop\word.py, line 17, in
Initialize
TypeError: expected clr.Reference, got str
> Process Exit Code: 1
> Time Taken: 00:07
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20090603/f296c660/attachment.html>
More information about the Ironpython-users
mailing list