Automating OpenOffice

This example starts OpenOffice, creates a new document and writes the text “The first line in the newly created text document.” to it.

import win32com.client

objServiceManager = win32com.client.Dispatch("")
objDesktop = objServiceManager.CreateInstance("")

args = []
objDocument = objDesktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, args)
objText = objDocument.GetText()
objCursor = objText.createTextCursor()
objText.insertString(objCursor, "The first line in the newly created text document.\n", 0)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.