RE: [IronPython] Word Automation

2005-06-20 Thread Martin Maly
Hi,

Tim already answered the first problem you faced, let's see if I can
help with the others.

 I do not understand why I cannot iterate in the collection of
Documents

While the collection you get back may (and I am not sure whether it does
or not) inherit from IEnumerable,
the code I put in IronPython doesn't detect it yet so we cannot iterate
it the tradiional Pythonic way. Anthony
Tarlano and I played with this already and we have been successful using
methods Count and Item on the 
collection (the collection we enumerated was collection of spelling
correction hints):

 import sys
 sys.LoadAssemblyByName('Microsoft.Office.Interop.Word')
 import Microsoft.Office.Interop.Word as Word
 wapp = Word.ApplicationClass()
 wapp.Documents.Add()
com_object Microsoft.Office.Interop.Word.DocumentClass
 s = wapp.GetSpellingSuggestions('tonny')

 for i in xrange(s.Count):
... print s.Item(i + 1).Name

...
tinny
Tony
tiny
sonny
tone
 

Same goes for collection of documents:

 import sys
 sys.LoadAssemblyByName(Microsoft.Office.Interop.Word)
 import Microsoft.Office.Interop.Word as wordApp
 mApp = wordApp.ApplicationClass()
 mApp.Visible=True
 mApp.Documents.Open(D:\\a.doc)
 mApp.Documents.Add()
 for i in xrange(mApp.Documents.Count):
... print mApp.Documents.Item(i + 1).Name
...
Document1
a.doc

 
  I cannot select a given document using its Name 

I was able to access the document by name using slightly modified code:

 print mApp.Documents.Item(X.doc).Name
x.doc

 I would like to translate the following vb statement in python
 Documents.Open FileName:=C:\Files\Doc.doc, ReadOnly:=True

 doc3 = mApp.Documents.Open(FileName='c:\tmp\Doc1.doc', ReadOnly=
True)

Passing parameters by name to COM objects is not implemented in
IronPython.

To open document read only, you can do following:

 mApp.Documents.Open(D:\\x.doc, False, True)

The 3rd parameter is Read Only. The rest of the parameters have
default values,
which IronPython will add.

The COM support in IronPython is going to be extended to get the best
possible experience. Currently the support is only very simple.

I hope this helps a little.

Martin
___
users-ironpython.com mailing list
users-ironpython.com@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


[IronPython] Word Automation

2005-06-19 Thread kbond

Hello,

Congratulation, for this new release correcting some bugs around the
PIA ComObject Operations.
I spent the last hours playing around with this great feature of ironpython and 
 I would like to share with you a couple
of things.
Some are working fine some seems strange to me but it
might be because I am missing something and some that are not working.



Scenario 1

IronPython 0.7.6 on .NET 2.0.50215.44
Copyright (c) Microsoft Corporation. All rights reserved.


import sys
sys.LoadAssemblyByName(Microsoft.Office.Interop.Word)
import Microsoft.Office.Interop.Word as wordApp
mApp= wordApp.ApplicationClass()
mApp.visible
 


False


mApp.visible = True
mApp.Documents.Open(c:\tmp\Doc1.doc)
 


System.Runtime.InteropServices.COMException: The document name or path is not va
lid.
Try one or more of the following:
* Check the path to make sure it was typed correctly.
(c:mp\Doc1.doc)click Open. Search for the file using this dialog box.
  at input_6.Run(Frame frame)



 


### I do not undertstand why this is not working however a
slightly modified  statement is working well##



doc1 = mApp.Documents.Open(r'c:\tmp\Doc1.doc')
doc1.Save()
doc1.Close()
 




Scenario 2


doc1 = mApp.Documents.Open(r'c:\tmp\Doc1.doc')
doc2 = mApp.Documents.Add()
doc2.SaveAs(rc:\tmp\Doc2.doc)
for i in mApp.Documents:
 


... print i.Name
...
System.Runtime.InteropServices.COMException: Unknown name. (Exception from HRESU
LT: 0x80020006 (DISP_E_UNKNOWNNAME))
  at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr,
Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[]
namedParameters)
  at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Bi
nder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers
, CultureInfo culture, String[] namedParams)
  at input_24.Run(Frame frame)

## I do not understand why I cannot iterate in the collection of
Documents##
## May be this is not supposed to work but it would be amazingly
efficient



mApp.Documents(Doc1.doc).Activate()
 


System.Runtime.InteropServices.COMException: Unknown name. (Exception from HRESU
LT: 0x80020006 (DISP_E_UNKNOWNNAME))
  at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr,
Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[]
namedParameters)
  at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Bi
nder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers
, CultureInfo culture, String[] namedParams)
  at input_29.Run(Frame frame)

# Another problem when working with a collection of documents #
# I cannot select a given document using its Name #

Scenario 3
# I would like to translate the following vb statement in python##
#vb Documents.Open FileName:=C:\Files\Doc.doc, ReadOnly:=True

doc3 = mApp.Documents.Open(FileName='c:\tmp\Doc1.doc', ReadOnly= True)


System.Exception: this object is not callable with keyword parameters
  at input_32.Run(Frame frame)

 Obviously, my guess was wrong but I do not have any idea on how
to do such thing any advise would be more than welcome##


Could you please help me to positionned win32com and IronPython?
Would it be possible to do the same things with IronPython than with win32com?
Thank you very much for your answers, I hope that will help you .

Regards


___
users-ironpython.com mailing list
users-ironpython.com@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Word Automation

2005-06-19 Thread Tim Riley
snip
  mApp.Documents.Open(c:\tmp\Doc1.doc)
 
 
 System.Runtime.InteropServices.COMException: The document name or path is not 
 va
 lid.
 Try one or more of the following:
 * Check the path to make sure it was typed correctly.
  (c:mp\Doc1.doc)click Open. Search for the file using this dialog box.
at input_6.Run(Frame frame)
/snip

You need to escape the backslashes. Should have been
c:\\tmp\\Doc1.doc. Also \t translate to a tab which is shown in the
error.

Tim Riley

On 6/19/05, kbond [EMAIL PROTECTED] wrote:
 Hello,
 
 Congratulation, for this new release correcting some bugs around the
 PIA ComObject Operations.
 I spent the last hours playing around with this great feature of ironpython 
 and  I would like to share with you a couple
 of things.
 Some are working fine some seems strange to me but it
 might be because I am missing something and some that are not working.
 
 
 
 Scenario 1
 
 IronPython 0.7.6 on .NET 2.0.50215.44
 Copyright (c) Microsoft Corporation. All rights reserved.
 
  import sys
  sys.LoadAssemblyByName(Microsoft.Office.Interop.Word)
  import Microsoft.Office.Interop.Word as wordApp
  mApp= wordApp.ApplicationClass()
  mApp.visible
 
 
 False
 
  mApp.visible = True
  mApp.Documents.Open(c:\tmp\Doc1.doc)
 
 
 System.Runtime.InteropServices.COMException: The document name or path is not 
 va
 lid.
 Try one or more of the following:
 * Check the path to make sure it was typed correctly.
  (c:mp\Doc1.doc)click Open. Search for the file using this dialog box.
at input_6.Run(Frame frame)
 
 
 
 
 ### I do not undertstand why this is not working however a
 slightly modified  statement is working well##
 
 
  doc1 = mApp.Documents.Open(r'c:\tmp\Doc1.doc')
  doc1.Save()
  doc1.Close()
 
 
 
 
 Scenario 2
 
  doc1 = mApp.Documents.Open(r'c:\tmp\Doc1.doc')
  doc2 = mApp.Documents.Add()
  doc2.SaveAs(rc:\tmp\Doc2.doc)
  for i in mApp.Documents:
 
 
 ... print i.Name
 ...
 System.Runtime.InteropServices.COMException: Unknown name. (Exception from 
 HRESU
 LT: 0x80020006 (DISP_E_UNKNOWNNAME))
at System.RuntimeType.InvokeDispMethod(String name, BindingFlags 
 invokeAttr,
 Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, 
 String[]
 namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, 
 Bi
 nder binder, Object target, Object[] providedArgs, ParameterModifier[] 
 modifiers
 , CultureInfo culture, String[] namedParams)
at input_24.Run(Frame frame)
 
 ## I do not understand why I cannot iterate in the collection of
 Documents##
 ## May be this is not supposed to work but it would be amazingly
 efficient
 
 
  mApp.Documents(Doc1.doc).Activate()
 
 
 System.Runtime.InteropServices.COMException: Unknown name. (Exception from 
 HRESU
 LT: 0x80020006 (DISP_E_UNKNOWNNAME))
at System.RuntimeType.InvokeDispMethod(String name, BindingFlags 
 invokeAttr,
 Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, 
 String[]
 namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, 
 Bi
 nder binder, Object target, Object[] providedArgs, ParameterModifier[] 
 modifiers
 , CultureInfo culture, String[] namedParams)
at input_29.Run(Frame frame)
 
 # Another problem when working with a collection of documents #
 # I cannot select a given document using its Name #
 
 Scenario 3
 # I would like to translate the following vb statement in python##
 #vb Documents.Open FileName:=C:\Files\Doc.doc, ReadOnly:=True
  doc3 = mApp.Documents.Open(FileName='c:\tmp\Doc1.doc', ReadOnly= True)
 
 System.Exception: this object is not callable with keyword parameters
at input_32.Run(Frame frame)
 
  Obviously, my guess was wrong but I do not have any idea on how
 to do such thing any advise would be more than welcome##
 
 
 Could you please help me to positionned win32com and IronPython?
 Would it be possible to do the same things with IronPython than with win32com?
 Thank you very much for your answers, I hope that will help you .
 
 Regards
 
 
 ___
 users-ironpython.com mailing list
 users-ironpython.com@lists.ironpython.com
 http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

___
users-ironpython.com mailing list
users-ironpython.com@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


RE: [IronPython] word Automation

2005-05-17 Thread Martin Maly



With some code changes in IronPython(the changes are 
not in 0.7.5) I was able to get this working as far as making word app visible. 
However I was not yet successful with the Documents collection 
access.
The object returned from the Documents property (and this 
was just a quick look, I am going to investiagate further when I am back) didn't 
have much type information with it so
IronPython didn't know how to use it. Thanks for the bug 
and I hope to have some answers soon.

Martin


  
  
  From: 
  [EMAIL PROTECTED] 
  [mailto:[EMAIL PROTECTED] On Behalf Of 
  Anthony TarlanoSent: Sunday, May 15, 2005 7:13 AMTo: 
  Discussion of IronPythonSubject: Re: [IronPython] word 
  Automation
  Hello,I finally found sometime this weekend to check out 
  IronPython's support for the Office2003 PIA's. Final impression is that 
  somethings work, but most didn't. Here's a link to the bug 
  I opened showing a small amount of interaction with the word application class 
  via the console. Anthony
___
users-ironpython.com mailing list
users-ironpython.com@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] word Automation

2005-05-15 Thread Anthony Tarlano
Hello,

I finally found sometime this weekend to check out IronPython's support
for the Office2003 PIA's. Final impression is that somethings work, but
most didn't. 

Here's a link to the bug I opened showing a small amount of interaction with the word application class via the console.


AnthonyOn 5/9/05, kbond [EMAIL PROTECTED] wrote:
Hello,First congratulation of all, thank you for the tremendous work that youhave already done.I am looking forward the day where I will be able to translate all my MSofficeautomation in pythonscripts.
Am I correct I say that iron python will allow it?So today I try to give it a try but unfortunatly withou success till now.I am trying to translate this simple vb.net module to iron python, is
there someone reading this list that can help me?the VBImports word = Microsoft.Office.Interop.wordModule Module1Sub Main()Dim oWord As Word.ApplicationClass'Start Word and open the document.
oWord = CreateObject(Word.Application)oWord.Visible = TrueoWord.Documents.Open(C:\tmp\Doc1.doc)'Run the macros.'oWord.Run(DoKbTest)
'oWord.Run(DoKbTestWithParameter, Hello from VB .NET Client)'Quit Word.oWord.Quit()System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord)
oWord = NothingEnd SubEnd ModuleIron Pythonimport syssys.LoadAssemblyByName(Microsoft.Office.Interop.Word)import Microsoft.Office.Interop.Word as wordApp
oWord = wordApp.ApplicationClassoWord = CreateObject(wordApp.Application)oWord.Visible = TrueoWord.Documents.Open(C:\tmp\Doc1.doc)oWord.Quit()System.Runtime.InteropServices.Marshal.ReleaseComObject
(oWord)oWord = Nothingthank you___users-ironpython.com mailing list
users-ironpython.com@lists.ironpython.comhttp://lists.ironpython.com/listinfo.cgi/users-ironpython.com___
users-ironpython.com mailing list
users-ironpython.com@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] Word Automation

2005-05-10 Thread Anthony Tarlano
Yann,

I found the information that I needed concorning the Office 2003
primary interop assemblies (PIAs) at
http://msdn.microsoft.com/library/default.asp?url=""


I have not had a chance to look into the PIA deeper, but I will try to get to is as soon as I find sometime..

Regards,

AnthonyOn 5/9/05, Yann [EMAIL PROTECTED] wrote:
Hello Anthony,Since I am not sure to understand you request:If you tell me how to get the assembly having Microsoft.Office.Interop.WordI will try it out for you and post back the code snippet.
I googled to find some answers.Here it is what I found:http://msdn.microsoft.com/library/default.asp?url=""
I hope that help you to help me...However I haven't done this I have just add reference to COM librairy Microsoft Word 11.0 Object...I have just check in my c:\WINDOWS\assembly and I can see 
Microsoft.Office.Interop.word.thank you for your helpRegards___users-ironpython.com mailing list
users-ironpython.com@lists.ironpython.comhttp://lists.ironpython.com/listinfo.cgi/users-ironpython.com___
users-ironpython.com mailing list
users-ironpython.com@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] word Automation

2005-05-09 Thread Anthony Tarlano
Hi,

Yes it should work, but I don't have the correct assembly to be able to test it.

You should remember that you should just translate the code from VB to
IronPython. IronPython is a dynamically bound language, so you don't
have to do things like declaring the local variable oWord (i.e. 'oWord
= wordApp.ApplicationClass') 

In python an variable object is bound to a type upon assignment to an Rvalue object

If you tell me how to get the assembly having
Microsoft.Office.Interop.Word I will try it out for you and post back
the code snippet.

AnthonyOn 5/9/05, kbond [EMAIL PROTECTED] wrote:
Hello,First congratulation of all, thank you for the tremendous work that youhave already done.I am looking forward the day where I will be able to translate all my MSofficeautomation in pythonscripts.
Am I correct I say that iron python will allow it?So today I try to give it a try but unfortunatly withou success till now.I am trying to translate this simple vb.net module to iron python, is
there someone reading this list that can help me?the VBImports word = Microsoft.Office.Interop.wordModule Module1Sub Main()Dim oWord As Word.ApplicationClass'Start Word and open the document.
oWord = CreateObject(Word.Application)oWord.Visible = TrueoWord.Documents.Open(C:\tmp\Doc1.doc)'Run the macros.'oWord.Run(DoKbTest)
'oWord.Run(DoKbTestWithParameter, Hello from VB .NET Client)'Quit Word.oWord.Quit()System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord)
oWord = NothingEnd SubEnd ModuleIron Pythonimport syssys.LoadAssemblyByName(Microsoft.Office.Interop.Word)import Microsoft.Office.Interop.Word as wordApp
oWord = wordApp.ApplicationClassoWord = CreateObject(wordApp.Application)oWord.Visible = TrueoWord.Documents.Open(C:\tmp\Doc1.doc)oWord.Quit()System.Runtime.InteropServices.Marshal.ReleaseComObject
(oWord)oWord = Nothingthank you___users-ironpython.com mailing list
users-ironpython.com@lists.ironpython.comhttp://lists.ironpython.com/listinfo.cgi/users-ironpython.com___
users-ironpython.com mailing list
users-ironpython.com@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


Re: [IronPython] word Automation

2005-05-09 Thread Anthony Tarlano
That should have read you should not just translate the...

AnthonyOn 5/9/05, Anthony Tarlano [EMAIL PROTECTED] wrote:
Hi,

Yes it should work, but I don't have the correct assembly to be able to test it.

You should remember that you should just translate the code from VB to
IronPython. IronPython is a dynamically bound language, so you don't
have to do things like declaring the local variable oWord (i.e. 'oWord
= wordApp.ApplicationClass') 

In python an variable object is bound to a type upon assignment to an Rvalue object

If you tell me how to get the assembly having
Microsoft.Office.Interop.Word I will try it out for you and post back
the code snippet.

AnthonyOn 5/9/05, kbond 
[EMAIL PROTECTED] wrote:
Hello,First congratulation of all, thank you for the tremendous work that youhave already done.I am looking forward the day where I will be able to translate all my MSofficeautomation in pythonscripts.
Am I correct I say that iron python will allow it?So today I try to give it a try but unfortunatly withou success till now.I am trying to translate this simple 
vb.net module to iron python, is
there someone reading this list that can help me?the VBImports word = Microsoft.Office.Interop.wordModule Module1Sub Main()Dim oWord As Word.ApplicationClass'Start Word and open the document.
oWord = CreateObject(Word.Application)oWord.Visible = TrueoWord.Documents.Open(C:\tmp\Doc1.doc)'Run the macros.'oWord.Run(DoKbTest)
'oWord.Run(DoKbTestWithParameter, Hello from VB .NET Client)'Quit Word.oWord.Quit()System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord)
oWord = NothingEnd SubEnd ModuleIron Pythonimport syssys.LoadAssemblyByName(Microsoft.Office.Interop.Word)import Microsoft.Office.Interop.Word as wordApp
oWord = wordApp.ApplicationClassoWord = CreateObject(wordApp.Application)oWord.Visible = TrueoWord.Documents.Open(C:\tmp\Doc1.doc)oWord.Quit()System.Runtime.InteropServices.Marshal.ReleaseComObject

(oWord)oWord = Nothingthank you___users-ironpython.com
 mailing list
users-ironpython.com@lists.ironpython.comhttp://lists.ironpython.com/listinfo.cgi/users-ironpython.com

___
users-ironpython.com mailing list
users-ironpython.com@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


[IronPython] word Automation

2005-05-08 Thread kbond
Hello,
First congratulation of all, thank you for the tremendous work that you 
have already done.
I am looking forward the day where I will be able to translate all my MS 
office  automation in python  scripts.

Am I correct I say that iron python will allow it?
So today I try to give it a try but unfortunatly withou success till now.
I am trying to translate this simple vb.net module to iron python, is 
there someone reading this list that can help me?

the VB
Imports word = Microsoft.Office.Interop.word
Module Module1
   Sub Main()
   Dim oWord As Word.ApplicationClass
   'Start Word and open the document.
   oWord = CreateObject(Word.Application)
   oWord.Visible = True
   oWord.Documents.Open(C:\tmp\Doc1.doc)
   'Run the macros.
   'oWord.Run(DoKbTest)
   'oWord.Run(DoKbTestWithParameter, Hello from VB .NET Client)
   'Quit Word.
   oWord.Quit()
   System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord)
   oWord = Nothing
   End Sub
End Module
Iron Python
import sys
sys.LoadAssemblyByName(Microsoft.Office.Interop.Word)
import Microsoft.Office.Interop.Word as wordApp
oWord = wordApp.ApplicationClass
oWord = CreateObject(wordApp.Application)
oWord.Visible = True
oWord.Documents.Open(C:\tmp\Doc1.doc)
oWord.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord)
oWord = Nothing
thank you
___
users-ironpython.com mailing list
users-ironpython.com@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com