UNO automation with a binary (executable)

From Apache OpenOffice Wiki
Revision as of 15:53, 15 May 2006 by SergeMoutou (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

We want now discuss a fully UNO/ program : we mean a program which automates some tasks on 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 : “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.

  1. the ServiceManager
  2. 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>
cd examples/DevelopersGuide/ProfUNO/CppBinding

which only writes out "Connected successfully to the office". Under Windows it would be :

cd <OpenOffice.org1.1_SDK>
cd examples/DevelopersGuide/ProfUNO/CppBinding
Personal tools