472,090 Members | 1,325 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,090 software developers and data experts.

Creating MS Word documents

144 100+
Hey everybody,

After looking on the internet, I found that a way to create word documents is using the win32com object.

The easy part is
winapp = win32com.client.Dispatch("Word.Application")
windoc = winapp.Documents.Add()

And as far as I have found you have the contents and font part, but how can I add images, tables, headers, footers, ...

Is there an API somewhere, or a book somewhere that would explain to me how this works?

I have found a link to the Word Object Model from Microsoft, but that is a bit of a mess to work with.


Thx in advance
Mar 17 '09 #1
2 7683
144 100+
After further research I found some interesting information that other people might find interesting too.

In your Lib/site-packages/win32com/client there is a tool that is called makepy.py
When you execute this file with python, you get a list with all the COM objects installed on the computer. Select the Word COM object and click OK. It will start generating a python file
if you open that file and look for the class _Application you see a list of available commands


Expand|Select|Wrap|Line Numbers
  1. import win32com.client
  2. wordapp = win32com.client.Dispatch("Word.Application")
  3. wordapp.Visible=1
  4. wordapp.ListCommands()
That should open a document with a list of all the commands you have available. Use the previous method to find additional arguments. Allthougt if somebody has any other references feel free to still post them here.
Mar 17 '09 #2
2,851 Expert Mod 2GB
Thanks micmast for the information. I had to pass an integer argument to ListCommands() for it to work though.
Expand|Select|Wrap|Line Numbers
  1. wordapp.ListCommands(1)
Python 2.3.5
Mar 20 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by vinod | last post: by
6 posts views Thread by Fred Glickman via AccessMonster.com | last post: by
12 posts views Thread by enak | last post: by
reply views Thread by Deepankar Raizada | last post: by
reply views Thread by Eagle | last post: by
3 posts views Thread by Brian Cryer | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.