[Tutor] Python and Excel

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Mon, 3 Jun 2002 23:08:44 -0700 (PDT)


On Tue, 4 Jun 2002, Laura Cantero wrote:

> How can I export data strings from a .txt file,

Hi Laura,

This depends on how your data is formatted.  Python strings support
several utility functions you can use to parse out the data.  If it's in
tab-delimited format, you'll find the 'split()' string method pretty
useful.  Here's an example of how it might work:

###
>>> sample_line = 'hello world, this is a test'
>>> words = sample_line.split(' ')
>>> words
['hello', 'world,', 'this', 'is', 'a', 'test']
###

This example shows that we can split a line along space boundaries, and we
can do similar stuff with tabs if that's how your file is organized.  But
Excel already has the ability to load tab-delimited data, so perhaps your
information has some structure to it.  Tell us more information about the
file format, and we'll try giving suggestions.



> and display them on Excel (individually)??? I need the CODE! Thanks,

It sounds like you're planning to do win32 stuff.  I'd recommend taking a
look at "Python Programming on Win32":

    http://www.oreilly.com/catalog/pythonwin32/chapter/ch12.html

I'm almost positive there's a chapter in there about driving Excel, so
looking through that book will be helpful.


Also, try contacting the python-win32 list; there are Windows experts
there who might be able to cook up a nice example for you.  Their mailing
list is here:

    http://mail.python.org/mailman/listinfo/python-win32


Do you have experience in Python already?  If you tell us more about what
you've tried already, we can tailor our responses better.


Hope this helps!