[python-win32] filling in field in a Word doc?
sharpblade
sharpblade1 at gmail.com
Wed Jul 13 20:14:26 CEST 2011
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
>
More information about the python-win32
mailing list