I want to impress the boss.

Mike Fletcher mfletch at tpresence.com
Mon Oct 16 01:16:45 EDT 2000


VSS integration is found in PythonWin, you can root it out of the code in
Pythonwin\pywin\framework\editor\vss.py .  It's just a regular COM object.

Word Automation (another COM object, as is almost everything from MS), can
be had by going to PythonWin|Tools|MakePy then choosing the appropriate Word
version (unfortunately, almost every version is different in the exposed
interfaces).  You could then open the (generated) file, which will be some
god-awful-hideously named thing (it uses the GUID as the filename) in:

$PythonDir$\win32com\gen_py\

For Office 2000 Professional (Word 9), the file was:

00020905-0000-0000-C000-000000000046x0x8x1.py

At the top will be a definition of all the exposed constants in the app
(there's a _lot_ of them in Word), then a long set of objects that are the
"implementation" of the COM interface.  Normally what you do is you decide
what you're interested in, for instance:
	I want to find a particular table in the document
	I want to update a particular column in that document

And from there decide which objects are interesting (document, table).  If
you're more methodically minded, you can actually look at the VB for
Applications docs that come with Word and find the objects that way (but
it's less fun, since you don't get to poke through all the weird little
corners of Word).  If you're like me, you just load up a file in Word and
poke around until you find the objects you want, guessing at the names until
you get the ones you want (PythonWin shows you the attributes, so it's
really not that hard to do this).

As an example, here's a sample where I open a document with a single table
and alter the contents of a cell in a table:

>>> Generating to
D:\bin\lang\Python\win32com\gen_py\00020905-0000-0000-C000-000000000046x0x8x
1.py
>>> import win32com
>>> o = win32com.client.Dispatch("Word.Application")
>>> o.Visible = 1 # not likely necessary for an automated task, but makes
debugging easier...
>>> o.Documents.Open( "z:\\a table file.doc" )
<win32com.gen_py.Microsoft Word 9.0 Object Library.Document>
>>> o.Documents[0]
<win32com.gen_py.Microsoft Word 9.0 Object Library.Document>
>>> doc = o.Documents[0] # seems to be 0-based
>>> table = doc.Tables[0] # seems to be 0-based
>>> table
<win32com.gen_py.Microsoft Word 9.0 Object Library.Table>
>>> table.Cell( 0,1 )
<win32com.gen_py.Microsoft Word 9.0 Object Library.Cell>
>>> cell = table.Cell( 1,2 ) # note, 1-based indices
>>> cell.Range.Text = "Hello world1"
>>> cell = table.Cell( 2,2 )
>>> cell.Range.Text = "Hello world2"
>>> 

As you can see, I have no clue what I'm doing, so take with a couple healthy
tblspoons of salt, but it might get you started.  HTH,
Mike

-----Original Message-----
From: chrisgarland at i-rocket.net [mailto:chrisgarland at i-rocket.net]
Sent: Monday, October 16, 2000 12:15 AM
To: python-list at python.org
Subject: I want to impress the boss.


I'm new to Python and am trying to get my company to adopt it as
a 'quick and dirty' glue tool.  I would like to assemble a
demonstration for my boss that would undeniably convince him.  What I'd
like to do is
get Python to:
- Ask the user what project they'd like updated.
- Open Visual Source Safe (VSS) and move the projects files into a
newly created directory.
- Run and record a checksum over every file in the directory.
- Open the project's Word document and have the appropriate table
update the checksums.

I bought a copy of "Python Programming on Win32" which has helped speed
me along but I still need help.
- Where could I find a full set of commands that I can issue to Word
from Python?
- Is there a COM interface to VSS? or can I issue 'DOS prompt' like
commands to VSS to get it to release its files to me.

Thanks, ANY help would be helpful.


Sent via Deja.com http://www.deja.com/
Before you buy.
-- 
http://www.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list