[python-win32] filling in field in a Word doc?
Bill Allen
wallenpb at gmail.com
Wed Jul 13 21:15:46 CEST 2011
The bookmarks way look very useable. I will have to give that a try when I
create one of these from scratch. At the moment, I am looking at having to
support a Word document with form fields already in it. Not sure that is
the way I would have done it myself, but it is what I have to work with.
Thanks,
Bill
On Wed, Jul 13, 2011 at 13:14, sharpblade <sharpblade1 at gmail.com> wrote:
> I have been doing a lot of work with Word and pywin32, it is a
> nightmare (Especially with formatting). If you want to populate
> pre-defined fields then the easiest way I have found is to create a
> template document and fill it with bookmarks, then pretty much do
> this:
>
> document.Bookmarks("my_bookmark").Range.Text = "Hello"
>
> This will put "Hello" wherever you have bookmarked "my_bookmark".
> Works for tables and other items as well.
>
> On Wed, Jul 13, 2011 at 6:56 PM, Tim Roberts <timr at probo.com> wrote:
> > Bill Allen wrote:
> >> I have the process for using win32com.client to create and put text
> >> into a Word document. How about filling in fields in an existing
> >> Word document? I am looking for more information on working with MS
> >> Word documents using the Python win32 facilities.
> >
> > We've just been having this discussion. The hard part is figuring out
> > which functions in the Word object model will do what you need. After
> > you know which functions you need, it's relatively easy to convert the
> > VB or C# code to Python.
> >
> > In this case, the Document object contains a Fields collection that hold
> > all of the fields in the document. You will probably need to run
> > through the fields in the Fields collection, figure out which ones are
> > fill-in fields (as opposed to page number fields, or date fields, or one
> > of the other thousand field types), and change the value.
> >
> > --
> > Tim Roberts, timr at probo.com
> > Providenza & Boekelheide, Inc.
> >
> > _______________________________________________
> > python-win32 mailing list
> > python-win32 at python.org
> > http://mail.python.org/mailman/listinfo/python-win32
> >
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20110713/5273a94a/attachment.html>
More information about the python-win32
mailing list