UNO automation with a binary (executable)
We want now discuss a fully UNO/OpenOffice.org program : we mean a program which automates some tasks on OpenOffice.org documents, file loading, file modifying, file saving... all in all “Create a binary program to replace a OOoBasic program”. The border between the examples of previous chapter and of this chapter is vague. I can only say : if you imagine to automate any problem and create a program for, this paragraph and the next chapters are for you.
Introduction : starting from a SDK example
Danny Brewer wrote in the Openoffice forum : http://www.oooforum.org/forum/viewtopic.php?t=5252 “To do almost anything useful with OOo via. the API, in almost all cases, you must either create a new document, or open an existing document. Then you would manipulate the contents of the document, extract information from it, print it, convert it to a different format, work with data forms on the document, or perform various other tasks with office documents.
Therefore, one of the first things to learn is how to open or create documents.
ServiceManager and Desktop objects
In order to work with OOo via. the API, you must first acquire two essential objects.
- the ServiceManager
- the Desktop
Once you have the ServiceManager, you call its createInstance() method to get the Desktop object. Once you have the Desktop object, you can use it to create or open new documents.
Getting the Service Manager
In every different programming language, there are different mechanisms for acquiring the Service Manager.” One way of getting the service manager is given in one SDK example : <OpenOffice.org1.1_SDK>/examples/DevelopersGuide/ProfUNO/CppBinding We first check the example (under Linux) :
cd <OpenOffice.org1.1_SDK> ./setsdkenv_unix cd examples/DevelopersGuide/ProfUNO/CppBinding make make Office_connect.run
which only writes out "Connected successfully to the office". Under Windows it would be :
cd <OpenOffice.org1.1_SDK> setsdkenv_windows cd examples/DevelopersGuide/ProfUNO/CppBinding make make Office_connect.run