Creating MS Word documents

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • micmast
    New Member
    • Mar 2008
    • 144

    Creating MS Word documents

    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.Document s.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.

    Gain technical skills through documentation and training, earn certifications and connect with the community


    Thx in advance
  • micmast
    New Member
    • Mar 2008
    • 144

    #2
    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

    [CODE=python]
    import win32com.client
    wordapp = win32com.client .Dispatch("Word .Application")
    wordapp.Visible =1
    wordapp.ListCom mands()
    [/CODE]

    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.

    Comment

    • bvdet
      Recognized Expert Specialist
      • Oct 2006
      • 2851

      #3
      Thanks micmast for the information. I had to pass an integer argument to ListCommands() for it to work though.
      Code:
      wordapp.ListCommands(1)
      Python 2.3.5

      Comment

      Working...