Thanks a lot Shri ! That helped. I was having the 1.x version of Iron Python .
On Wed, Jun 3, 2009 at 7:29 PM, Shri Borde <[email protected]> wrote: > Try using this workaround. > > > > import clr > > r = clr.Reference[str]() > > r.Value = source_filename > > word_application.Documents.Open(r) > > > > You should not have to do this with IPy 2.6, and probably even with 2.0. > Using a str directly works for me. What version of IronPython are you using? > I think the workaround might have been needed with IPy 1.X. > > > > See > http://blogs.msdn.com/shrib/archive/2008/07/30/idispatch-support-on-in-ironpython-beta-4.aspxfor > some details about using COM from IPy. > > > > Thanks, > > Shri > > > > *From:* [email protected] [mailto: > [email protected]] *On Behalf Of *Sivaguru Perambalam > *Sent:* Wednesday, June 03, 2009 1:36 PM > *To:* [email protected] > *Subject:* [IronPython] Urgent : Unable to open MS Word file from Python > > > > 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 > > _______________________________________________ > Users mailing list > [email protected] > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > >
_______________________________________________ Users mailing list [email protected] http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
