How to learn to use python with Excel

X

Xiao-Qin Xia

I don't like VBA, and want to use python to work with Excel. Does
anybody recommend some good documents to begin with?

Many thanks,

Xiao-Qin
 
P

Peter Hansen

Xiao-Qin Xia said:
I don't like VBA, and want to use python to work with Excel. Does
anybody recommend some good documents to begin with?

Mark Hammond and Andy Robinson's book
(http://www.oreilly.com/catalog/pythonwin32/index.html) has good
coverage of such things. You can even read it online if you
subscribe to Safari.

There are also probably dozens of examples you can find on the
net here and there, or in the newsgroup/mailing list archives.
For example, this search should get you started:
http://groups.google.com/groups?q=group:comp.lang.python.*+excel.application

-Peter
 
C

Christopher T King

I don't like VBA, and want to use python to work with Excel. Does
anybody recommend some good documents to begin with?

As a quick-start example, this Python:

from win32com.client import Dispatch
excel = Dispatch("Excel.Application")

is equivalent to this VB:

Dim excel As Application
excel = CreateObject("Excel.Application")

After that, some calls even look identical:

ws = excel.ActiveSheet

eqv. to:

Dim ws as Worksheet
ws = excel.ActiveSheet

Any differences (I can't think of any off the top of my head) will likely
be found through trial and error... one major difference is that, in
addition to properties, VB doesn't want parenthesis after Sub calls
(functions of no arguments), whereas Python does. Fortunately it's pretty
easy to tell with Python; you'll either get a function object or an error
if you guess wrong (as I may have above).

win32com is included in the ActiveState distribution; if you otherwise
don't have it (unlikely), you can download it at
http://www.python.org/windows/win32com/.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,205
Messages
2,571,067
Members
47,673
Latest member
MahaliaPal

Latest Threads

Top