By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,676 Members | 2,249 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,676 IT Pros & Developers. It's quick & easy.

Creating MS Word documents

micmast
100+
P: 144
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.

http://msdn.microsoft.com/en-us/library/bb244515.aspx

Thx in advance
Mar 17 '09 #1
Share this Question
Share on Google+
2 Replies


micmast
100+
P: 144
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

Or

Expand|Select|Wrap|Line Numbers
  1. import win32com.client
  2. wordapp = win32com.client.Dispatch("Word.Application")
  3. wordapp.Visible=1
  4. wordapp.ListCommands()
  5.  
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

bvdet
Expert Mod 2.5K+
P: 2,851
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.