469,314 Members | 2,212 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,314 developers. It's quick & easy.

Creating MS Word documents

micmast
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.

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

Thx in advance
Mar 17 '09 #1
2 7550
micmast
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

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
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
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.