Staroffice™ Programmer's Tutorial
Total Page:16
File Type:pdf, Size:1020Kb
StarOffice Programmer’s Tutorial Sun Microsystems, Inc. 901 San Antonio Road Palo Alto, CA 94303-4900 U.S.A. Part Number 806-5845 May 2000 Copyright 2000 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California 94303-4900 U.S.A. All rights reserved. This product or document is protected by copyright and distributed under licenses restricting its use, copying, distribution, and decompilation. No part of this product or document may be reproduced in any form by any means without prior written authorization of Sun and its licensors, if any. Third-party software, including font technology, is copyrighted and licensed from Sun suppliers. Parts of the product may be derived from Berkeley BSD systems, licensed from the University of California. UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open Company, Ltd. Sun, Sun Microsystems, the Sun logo, docs.sun.com, AnswerBook, AnswerBook2, and Solaris are trademarks, registered trademarks, or service marks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the U.S. and other countries. Products bearing SPARC trademarks are based upon an architecture developed by Sun Microsystems, Inc. The OPEN LOOK and SunTM Graphical User Interface was developed by Sun Microsystems, Inc. for its users and licensees. Sun acknowledges the pioneering efforts of Xerox in researching and developing the concept of visual or graphical user interfaces for the computer industry. Sun holds a non-exclusive license from Xerox to the Xerox Graphical User Interface, which license also covers Sun’s licensees who implement OPEN LOOK GUIs and otherwise comply with Sun’s written license agreements. Federal Acquisitions: Commercial Software–Government Users Subject to Standard License Terms and Conditions. DOCUMENTATION IS PROVIDED “AS IS” AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID. Copyright 2000 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, Californie 94303-4900 Etats-Unis. Tous droits réservés. Ce produit ou document est protégé par un copyright et distribué avec des licences qui en restreignent l’utilisation, la copie, la distribution, et la décompilation. Aucune partie de ce produit ou document ne peut être reproduite sous aucune forme, par quelque moyen que ce soit, sans l’autorisation préalable et écrite de Sun et de ses bailleurs de licence, s’il y en a. Le logiciel détenu par des tiers, et qui comprend la technologie relative aux polices de caractères, est protégé par un copyright et licencié par des fournisseurs de Sun. Des parties de ce produit pourront être dérivées du système Berkeley BSD licenciés par l’Université de Californie. UNIX est une marque déposée aux Etats-Unis et dans d’autres pays et licenciée exclusivement par X/Open Company, Ltd. Sun, Sun Microsystems, le logo Sun, docs.sun.com, AnswerBook, AnswerBook2, et Solaris sont des marques de fabrique ou des marques déposées, ou marques de service, de Sun Microsystems, Inc. aux Etats-Unis et dans d’autres pays. Toutes les marques SPARC sont utilisées sous licence et sont des marques de fabrique ou des marques déposées de SPARC International, Inc. aux Etats-Unis et dans d’autres pays. Les produits portant les marques SPARC sont basés sur une architecture développée par Sun Microsystems, Inc. L’interface d’utilisation graphique OPEN LOOK et SunTM a été développée par Sun Microsystems, Inc. pour ses utilisateurs et licenciés. Sun reconnaît les efforts de pionniers de Xerox pour la recherche et le développement du concept des interfaces d’utilisation visuelle ou graphique pour l’industrie de l’informatique. Sun détient une licence non exclusive de Xerox sur l’interface d’utilisation graphique Xerox, cette licence couvrant également les licenciés de Sun qui mettent en place l’interface d’utilisation graphique OPEN LOOK et qui en outre se conforment aux licences écrites de Sun. CETTE PUBLICATION EST FOURNIE “EN L’ETAT” ET AUCUNE GARANTIE, EXPRESSE OU IMPLICITE, N’EST ACCORDEE, Y COMPRIS DES GARANTIES CONCERNANT LA VALEUR MARCHANDE, L’APTITUDE DE LA PUBLICATION A REPONDRE A UNE UTILISATION PARTICULIERE, OU LE FAIT QU’ELLE NE SOIT PAS CONTREFAISANTE DE PRODUIT DE TIERS. CE DENI DE GARANTIE NE S’APPLIQUERAIT PAS, DANS LA MESURE OU IL SERAIT TENU JURIDIQUEMENT NUL ET NON AVENU. Please Recycle Contents 1. Introduction 7 1.1 What this book is about 7 1.2 Who should read this book 8 1.3 What is StarOffice API 9 1.4 How you can use StarOffice API 9 1.5 Where to find additional information 10 1.6 Typographic conventions 10 2. StarOffice API - Concepts 13 2.1 Services and Interfaces 13 2.2 Modules 15 2.3 Components 16 3. Using StarOffice API - Basics 17 3.1 Getting a Service 17 3.1.1 Independent Services 17 3.1.2 Context-dependent services 18 3.1.3 Service Factories 20 3.1.4 Which services does StarOffice API provide 20 3.2 Properties 21 3.3 Collections and Containers 22 3 3.3.1 Named access 22 3.3.2 Index access 23 3.3.3 Enumeration access 24 3.4 Events 25 3.5 Understanding the StarOffice API Reference Manual 25 3.5.1 Properties 25 3.5.2 Types 26 3.5.3 Constants 28 3.5.4 URLs 28 4. Using StarOffice API - Building blocks 31 4.1 Styles 31 4.1.1 Style basics 32 4.1.2 Finding a suitable style 34 4.1.3 Defining your own style 34 4.1.4 Hard formatting 35 4.1.5 Headers, footers and tab stops 37 4.2 Importing, Exporting and Printing 41 4.2.1 Importing other Formats 41 4.2.2 Saving and exporting documents 43 4.2.3 Printing 44 4.3 Text 46 4.3.1 The structure of text documents 47 4.3.2 Moving around 51 4.3.3 Inserting and Changing text 52 4.3.4 Inserting paragraph breaks, special characters, and page breaks 53 4.3.5 Searching and replacing 55 4.3.6 Using regular expressions 57 4 StarOffice Programmer’s Tutorial ♦ May 2000 4.3.7 Inserting tables, frames, etc. 58 4.3.8 Locating text content 63 4.4 Sheet 64 4.4.1 Using Cells and Ranges 64 4.4.2 Formatting cells 70 4.4.3 Drawing a Chart from Data 74 4.5 Drawing 84 4.5.1 Creating simple shapes 87 4.5.2 Making things easier 90 4.5.3 Grouping objects 90 4.5.4 Creating sophisticated shapes 92 4.5.5 Manipulating shapes 95 5. Code Complete 99 5.1 Text 99 5.1.1 Modifying text automatically 99 5.1.2 Creating an index 103 5.2 Sheet 105 5.2.1 Adapting to Euroland 105 5.3 Drawing 107 5.3.1 Import/Export of ASCII files 107 5.4 Stock quotes updater 116 5.4.1 Retrieving URLs 117 5.4.2 Updating the tables 118 5.4.3 Updating the chart 119 5.5 Troubleshooting 121 5.5.1 Debugging 121 5.5.2 Displaying the object details 122 A. The UML Class Diagrams 125 Contents 5 A.1 UML 125 A.2 Stereotypes used by StarOffice API 125 A.3 Interface 126 A.4 Service 127 A.5 Relations used in the Class Diagrams 127 Glossary 131 6 StarOffice Programmer’s Tutorial ♦ May 2000 CHAPTER 1 Introduction We wish to acknowledge Christian Kirsch as the author of this tutorial.. 1.1 What this book is about This tutorial provides you with some recipes that should help you to program StarOffice. Although this software suite offers most of the features required in today’soffices, there are always tasks that are better handled with a small program. Most notably, a task requiring the same mouse clicks or text entries over and over again should be done by a program. StarOffice API permits you to automate tasks that would be tedious or hard to perform within StarOffice. For example, you can change many documents in one step or send email to a group of recipients selected from a database automatically. Furthermore, you can use StarOffice API to integrate StarOffice components into your own programs. The details of this integration are beyond the scope of this book, however. After you have read this book, you should have a fairly good knowledge of all StarOffice API components. However, we can’t provide you with detailed information for all services and interfaces. But you’ll learn how to use the StarOffice API Reference Manual, available as part of the StarOffice SDK, to find all the details you are interested in. The StarOffice Programmer’s Tutorial consists of several parts that should be read in sequence, since each chapter builds on the previous ones. This introduction contains general information on the whole book. Chapter 2 presents the parts that make up StarOffice API. In Chapter 3, you’ll see the basic techniques used in StarOffice API. 7 Chapter 4 contains examples of building blocks. These short programs can be used stand-alone or as parts of bigger applications. Finally, Chapter 5 features several larger programs that show you how to put the building blocks together. We chose the name "StarOffice Programmer’s Tutorial" to emphasize that this is neither a reference nor a user’s manual. Because we are focusing on examples that illustrate important aspects and usages of StarOffice API, this is not a complete description of all StarOffice API features.