On 12/13/07, Thomas Heller <[EMAIL PROTECTED]> wrote:
> Looking into the generated module, the "default" property
> with DISPID_VALUE is named '_Default'.
>
> In comtypes, there is currently no such magic.  You have to do this:
>
>   xxx.Cells._Default(1, 1)
>
Thanks. This is the answer I was hoping for. Looking at the
test_excel.py in comtypes test suite I found that I can use
xxx.Cells.Item[1, 1] which looks neater.

> It would probably be a good idea to change the "magic" that comtypes
> currently implements into something that is more compatible with VB
> (or other scripting languages).
> However, I fear that changing this may break some existing programs.
>
It would be good to have same conventions as VB because most of the
examples on web use it and similar syntax means lesser brain power
required :) But ultimately, only you can decide whether its
appropriate to make the change.

Continuing with the 'Range' object, I ran into a problem that it is
not iterable; although it provides _NewEnum member. I don't know if it
is a problem specific to my installation of Office 2000. I tried
following on the shell:

>>> from comtypes.client import CreateObject
>>> xl = CreateObject("Excel.Application")
>>> wb = xl.Workbooks.Add()
>>> rng = xl.Range['A1:C1']
>>> rng.Value[()] = (10,"20",31.4)
>>> for c in rng:
        print c.Value()

Traceback (most recent call last):
  File "<pyshell#10>", line 1, in <module>
    for c in rng:
TypeError: 'POINTER(Range)' object is not iterable

I think following test case would cover this scenario. My sincerest
apologies for not providing a proper patch but I don't have access to
svn now.
=============================================================
--- comtypes/test/test_excel.py Fri Nov 23 14:47:36 2007
+++ comtypes/test/test_excel.py Fri Dec 14 15:31:10 2007
@@ -51,6 +51,10 @@
                               ("x", "y", "z"),
                               (3.0, 2.0, 1.0)))

+        # Test for iteration support in 'Range' interface
+        self.failUnlessEqual([c.Value() for c in xl.Range["A1:C3"]],
+                             [10.0, 20.0, 31.4,
+                              "x", "y", "z",
+                              3.0, 2.0, 1.0])
+
         # With pywin32, one could write xl.Cells(a, b)
         # With comtypes, one must write xl.Cells.Item(1, b)

=============================================================

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users

Reply via email to