Writing text to a Word Document

G

gazathome

Hi everyone,

I am trying to write several attributes from a database table and
using the code below I can write the values however it is only
overwriting on the first line.

I am new to the win32com bit and I would like to know what is the
recommended reference to loop down the page and add multiple records
rather than the worddoc.Content.

I have read a little about writing this to an RTF or htmol but I am
getting information overload and going nowhere. Does anyone have a
nice tutorial out there that simply explains how to do this?

Much appreciated for any thoughts.

Cheers,

Gareth

import win32com.client, arcgisscripting, sys, os
gp = arcgisscripting.create(9.3)

#Create word document component - http://www.faqts.com/knowledge_base/view.phtml/aid/37034/fid/244
wordapp = win32com.client.Dispatch("Word.Application") # Create new
Word Object
wordapp.Visible = 1 # Word Application should`t be visible
worddoc = wordapp.Documents.Add() # Create new Document Object
worddoc.Content.Font.Size = 11
worddoc.Content.Paragraphs.TabStops.Add (100)

#Setup of GDB Connection
# Get the Featureclass from the Mobel - Property Box
PropBox = "C:\\Avon Fire Rescue\\data\AvonFire_1.gdb\\PropertyBox"

# Make a search cursor for the Property Box Feature class
PBselCur = gp.searchcursor(PropBox)
PBrow = PBselCur.reset()
PBrow = PBselCur.next()

#Using the search cursor get the Premise ID from a Property box

while PBrow:
PBrowVal = PBrow.getvalue("PremisesID")
#Add data to Word Document
worddoc.Content.Text = (PBrowVal)
PBrow = PBselCur.next()

#worddoc.Close() # Close the Word Document (a save-Dialog pops up)

print "Fin"
 
M

Mike Driscoll

Hi everyone,

I am trying to write several attributes from a database table and
using the code below I can write the values however it is only
overwriting on the first line.

I am new to the win32com bit and I would like to know what is the
recommended reference to loop down the page and add multiple records
rather than the worddoc.Content.

I have read a little about writing this to an RTF or htmol but I am
getting information overload and going nowhere.  Does anyone have a
nice tutorial out there that simply explains how to do this?

Much appreciated for any thoughts.

Cheers,

Gareth

import win32com.client, arcgisscripting, sys, os
gp = arcgisscripting.create(9.3)

#Create word document component -http://www.faqts.com/knowledge_base/view..phtml/aid/37034/fid/244
wordapp = win32com.client.Dispatch("Word.Application") # Create new
Word Object
wordapp.Visible = 1 # Word Application should`t be visible
worddoc = wordapp.Documents.Add() # Create new Document Object
worddoc.Content.Font.Size = 11
worddoc.Content.Paragraphs.TabStops.Add (100)

#Setup of GDB Connection
# Get the Featureclass from the Mobel - Property Box
PropBox = "C:\\Avon Fire Rescue\\data\AvonFire_1.gdb\\PropertyBox"

# Make a search cursor for the Property Box Feature class
PBselCur = gp.searchcursor(PropBox)
PBrow = PBselCur.reset()
PBrow = PBselCur.next()

#Using the search cursor get the Premise ID from a Property box

while PBrow:
    PBrowVal = PBrow.getvalue("PremisesID")
    #Add data to Word Document
    worddoc.Content.Text = (PBrowVal)
    PBrow = PBselCur.next()

#worddoc.Close() # Close the Word Document (a save-Dialog pops up)

print "Fin"

What you probably want is something like this:

rng = worddoc.Range(0,0)
while PBrow:
rng.InsertAfter(PBrowVal + "\r\n") # needs return and new line
character

At least, that's what I found in one of my books. It seemed to work
when I tested it in the interpreter.

Mike
 

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
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top