learn openoffice.org spreadsheet macro programming ooobasic and calc automation

216 878 0
learn openoffice.org spreadsheet macro programming ooobasic and calc automation

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

$ 39.99 US £ 24.99 UK € 36.99 EU Prices do not include local sales tax or VAT where applicable Packt Publishing Birmingham - Mumbai www.packtpub.com Learn OpenOffi ce.org Spreadsheet Macro Programming Calc is OpenOffice.org’s spreadsheet module. Like the rest of OpenOffice.org, Calc can be programmed using the built-in language OOoBasic. Both simple macros and complex applications can be developed in this language by controlling Calc through its object model. The book is compatible with StarBasic, the macro language for commercial version of OOo—StarOffi ce. This book teaches the OOoBasic language and the Calc object model, so that you can manipulate spreadsheets and data from within your programs. You will also see how to create dialog boxes and windows for friendly user interfaces, and how to integrate your spreadsheets with other applications, for example writing spreadsheet data to a document, or capturing data from a database, and using the spreadsheet to generate advanced calculations and reports. What you will learn from this book This well structured and practical tutorial will walk you though every step, and inspire you with great ways to save time and increase your productivity using Calc. • How to create custom Calc applications • Creating worksheet functions, automating repetitive tasks, creating new toolbars, menus, and dialog boxes • A complete guide to the IDE, language, and object model • Integrating Calc applications with other components of OpenOffi ce.org • Internet-based collaborative applications Who this book is written for You don’t need to be a programmer to use this book, but you do need to be familiar with the concept of a program and how simple things like a loop might work. If all you have is a taster of simple programs from high school then you will be fi ne. Learn OpenOffice.org Spreadsheet Macro Programming Dr. Mark Alexander Bain From T echnologies to Solutions Learn OpenOffi ce.org Spreadsheet Macro Programming OOoBasic and Calc Automation A fast and friendly tutorial to writing macros and spreadsheet applications Dr. Mark Alexander Bain Learn OpenOfce.org Spreadsheet Macro Programming OOoBasic and Calc Automation A fast and friendly tutorial to writing macros and spreadsheet applications Dr. Mark Alexander Bain BIRMINGHAM - MUMBAI Learn OpenOfce.org Spreadsheet Macro Programming OOoBasic and Calc Automation Copyright © 2006 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, Packt Publishing, nor its dealers or distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: December 2006 Production Reference: 1041206 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 1-84719-097-9 www.packtpub.com Cover Image by www.visionwt.com Credits Author Dr. Mark Alexander Bain Reviewer Andrew Pitonyak Development Editor David Barnes Technical Editors Divya Menon Saurabh Singh Editorial Manager Dipali Chittar Project Manager Patricia Weir Project Coordinator Suneet Amrute Indexer Bhushan Pangaonkar Proofreader Chris Smith Layouts and Illustrations Shantanu Zagade Cover Design Shantanu Zagade About the Author Dr. Mark Alexander Bain hasn't always been the leading authority on open-source software that you know him as now. Back in the late seventies he started work as a woodsman at Bowood Estates in Wiltshire. After that he spent a number of years working at Lowther Wildlife Park in Cumbria—it's not clear if his character made him suitable for looking after packs of wolves, or whether the experience made him the way he is now. In the mid eighties there was a general downturn in the popularity of animal parks in the UK, and Mark found himself out of work with two young sons (Simon and Michael) but with a growing interest in programming. His wife had recently bought him the state-of-the-art Sinclair ZX 81, and it was she who suggested that he went to college to study computing. Mark left college in 1989 and joined Vodafone—then a very small company—where he started writing programs using VAX/VMS. It was shortly after that, that he became addicted to something that was to drastically affect the rest of his life—Unix. His demise was further compounded when he was introduced to Oracle. After that there was no saving him. Over the next few years, Vodafone became the multinational company that it is now, and Mark progressed from Technician to Engineer, and from Engineer to Senior Engineer, and nally to Principal Engineer. At the turn of the century, general ill health made Mark reconsider his career; and his wife again came to his rescue when she saw a job advert for a lecturer at the University of Central Lancashire. It was also she who suggested that he should think about writing. Today Mark writes regularly for Linux Format, Newsforge.com, and Linux Journal. He's still teaching. And (apparently) he writes books as well. In memory of my Father—he would've got a real real kick out of this. Thanks to my Mother and my family for their continual (and continuing) support and encouragement. Thanks also to Noel Power and Michael Meeks for help with the chapter on VBA, to Paul Hudson for introducing me to Noel and Michael, to Andrew Pitonyak—I'm pleased that I could teach something to even you, and to David Barnes for that email back in May 2006. About the Reviewer Andrew Pitonyak is a Principal Research Scientist / Software Engineer for Battelle Memorial Institute. He has been using OpenOfce.org since it was StarOfce 5, and he is the author of "OpenOfce.org Macros Explained", "Andrew's Macro Document", and other OOo related documents (see http://www.pitonyak.org). He has a Master of Science degree in computer science and another in mathematics. In his spare time Andrew is very involved in his church, is a trained Stephen Minister and a professional puppeteer, works on his house, and spends time with his wife and daughter. He is an NRA‑certied rearms instructor, holds a General‑class amateur radio license, and spends a lot of time working with his digital camera. You can reach Andrew at andrew@pitonyak.org. Table of Contents Preface 1 Chapter 1: Working with OOo's Basic IDE 7 Before We Start 7 Accessing the OOo IDE 8 Controls in IDE 11 Navigating around the IDE 15 The Object Catalog 15 Select Macro 16 The OpenOfce.org Basic Macro Organizer 18 Designing Dialogs with the IDE 19 Summary 24 Chapter 2: Libraries, Modules, Subroutines, and Functions 25 Using Libraries 25 Managing Modules using Libraries 26 Using Libraries in a Multi-User Environment 28 Adding a Library to the OpenOfce.org Macros Area 33 Using Modules 35 Writing Macros 37 Writing Subroutines 38 Declare Variables 40 Assign Values to the Variables 40 Do the Work! 40 Inputting Variables 40 Writing Functions 41 Getting more Information 41 Subroutines and Functions in Different Libraries 42 Summary 43 Table of Contents [ ii ] Chapter 3: The OOo Object Model 45 Why be Interested in UNOs? 46 Overview of the OOo Object Model 46 The Interface 47 The Service 47 The Module 48 Starting to Work with UNOs 49 Opening and Closing Spreadsheets Automatically 50 Online Reference Material 54 A Real Example: Using the Table UNO to Access a Cell 59 Services within Services 61 Finding Included Services 62 List of Everything You Want to Know About UNOs 63 Summary 65 Chapter 4: Using Macros with Spreadsheets 67 Opening and Closing Spreadsheets 68 Manipulating Spreadsheet Cells 69 Using OOo's Built-in Functions 71 Named Worksheets and Cells 74 Accessing Existing Named Worksheets and Cells 74 Creating New Named Worksheets and Cells 75 Deleting Worksheets 75 Working with Multiple Spreadsheets 76 Using Ranges of Cells 79 Summary 79 Chapter 5: Formatting your Spreadsheets 81 The Most Basic Formatting—Column and Row Dimensions 82 Optimizing Column Widths 83 Optimizing Column Widths across a Whole Worksheet 83 Setting Fixed Widths and Heights 84 Hiding Columns 84 Formatting the Printed Page 84 Adding a Page Break 84 Dening a Print Area 85 Setting the Header and Footer 85 Adding Page Numbers 86 Setting the Page Size and Orientation 87 Customizing Worksheet Names 89 Updating the Document Information 89 Table of Contents [ iii ] Formatting Cells and Ranges of Cells 91 Changing Cell Styles 92 Changing Cell Formats 93 Cell Background Colors 93 Text Colors 93 Cell Fonts 94 Character Heights 94 The Underline 94 Word Wrapping 95 Number Formats 95 Online Reference Material 97 Summary 98 Chapter 6: Working with Databases 99 Accessing Databases 100 Which Databases can We Use? 100 Registering the Database as an OOo Data Source 101 Viewing Registered Data Sources 102 Connecting to a Database 103 Accessing Database Tables 103 Running Queries on the Tables 106 Putting it All into a Spreadsheet 108 Loading Data into Custom Worksheets 109 Adding New Records to the Database 113 Updating the Database 116 Summary 118 Chapter 7: Working with Other Documents 119 The OpenOfce.org Chart 120 Inserting a Simple Chart into a Spreadsheet 120 Formatting OpenOfce.org Charts 122 Chart Size 123 Chart Title 123 Adding Chart Axis Labels 124 Y Axis Text Orientation 124 A fully Formatted Bar Chart 124 Other Chart Types 126 Using Documents from Other Sources 127 Stock Market Analysis—Yahoo! Finance 128 Importing an Historical CSV File from Yahoo! Finance 130 Comparing Companies within Yahoo! Finance 134 Processing Web Pages 136 Summary 140 [...]... Available to Everyone Creating a Global Library Using a Global Library to Automate OOo Calc Running Macros Automatically when Calc Opens Adding Macros to the OpenOffice.org Calc Menu Adding a Macro to the Menu Manually Distributing a Menu Keeping It All Hidden Running Macros from the Command Line Running Macros in Linux Running Macros in MS Windows Creating Background or Batch Processes Running Background... automatically run a macro every time that you open your spreadsheet If you close this window (for now) and return to the OpenOffice.org Basic Macros dialog, then there's another button that you may be wondering about—Organizer Click it and you'll see the screen for the OpenOffice.org Basic Macro Organizer The OpenOffice.org Basic Macro Organizer A dialog that you'll see a lot of is the Basic Macro organizer:... groupings, and each one is used for a different purpose: 1 My Macros: If you want a macro to be used in all of your spreadsheets then store it here This is useful for commonly used functionality, but don't forget —if you email your spreadsheet to someone else, then the macros won't work (because, of course, each user will have their own 'My Macros') [] Working with OOo's Basic IDE 2 OpenOffice.org Macros:... Macros: If you want to write a macro that's to be available to spreadsheets used by all users on your system, then store it here 'OpenOffice.org Macros' is a system directory, so on Linux you will need root privileges to do this 3 penguin_private_investigations.ods: (You will, of course, see the name of your own spreadsheet here.) If the macro is to be embedded in the spreadsheet, and not to be used elsewhere,... clicking on Tools | Macros | Organize Macros | OpenOffice.org Basic) There are, however, some key differences: • The Existing macros in box is now populated with the macros that you've written • The Run, Assign, and Edit buttons are now enabled • There's no New button; it's been replaced by Delete So is this the same screen? Well, yes it is, and you can prove that to yourself by clicking on My Macros—immediately... skills in one of these then you don't need to learn a new programming language However, we will be only working in OpenOffice.org Basic, and so that's the option to choose from the menu As soon as you click on OpenOffice.org Basic , you'll be presented with the OpenOffice.org Basic Macros dialog: It's from here that you can choose where to create your first macro However, you've got a choice of areas... write your own macros By the end of the chapter you'll have become acclimatized to Calc' s development environment, and you'll know which buttons to press to make your life a little bit easier Chapter 2 starts to make use of the basic building blocks that you'll need for your macros: Libraries, Modules, Subroutines, and Functions By the end of the chapter you'll have your first macro up and running Chapter... the objects that are built into Calc, and which we can make use of in order to create macros that perform quite complex operations; we'll see just how easy they are to use We'll also see where to get further information on these objects Chapter 4 is where we really get into writing macros Here you'll learn how to manipulate the contents of one (or more) spreadsheets and after all, that's what we're... going to email your spreadsheet to someone else to use, or if you're going to store it on a network drive So, at the moment, we're only really going to be interested either in using My Macros or for the macro to be embedded into the spreadsheet When you are ready, highlight either My Macros or your new spreadsheet, then click New You'll now be presented with a New Module dialog box: And what is a module?... running, then use this button to end and let the current macro that you're in finish running normally You'll find these buttons extremely useful as you try to understand what's going on with your macros, especially if something is going on that you don't quite understand You can gain even more understanding by using another button The Watch button: As you step through the macro the values of variables in . Alexander Bain Learn OpenOfce .org Spreadsheet Macro Programming OOoBasic and Calc Automation A fast and friendly tutorial to writing macros and spreadsheet applications Dr. Mark Alexander. Mark Alexander Bain From T echnologies to Solutions Learn OpenOffi ce .org Spreadsheet Macro Programming OOoBasic and Calc Automation A fast and friendly tutorial to writing macros and spreadsheet. Mumbai www.packtpub.com Learn OpenOffi ce .org Spreadsheet Macro Programming Calc is OpenOffice .org s spreadsheet module. Like the rest of OpenOffice .org, Calc can be programmed using the built-in language OOoBasic.

Ngày đăng: 01/06/2014, 10:34

Từ khóa liên quan

Mục lục

  • Learn OpenOffice.org Spreadsheet Macro Programming

    • Table of Contents

    • Preface

    • Chapter 1: Working with OOo's Basic IDE

      • Before We Start

      • Accessing the OOo IDE

        • Controls in IDE

        • Navigating around the IDE

          • The Object Catalog

          • Select Macro

          • The OpenOffice.org Basic Macro Organizer

          • Designing Dialogs with the IDE

          • Summary

          • Chapter 2: Libraries, Modules, Subroutines, and Functions

            • Using Libraries

              • Managing Modules using Libraries

              • Using Libraries in a Multi-User Environment

              • Adding a Library to the OpenOffice.org Macros Area

              • Using Modules

              • Writing Macros

                • Writing Subroutines

                  • Declare Variables

                  • Assign Values to the Variables

                  • Do the Work!

                  • Inputting Variables

                  • Writing Functions

                  • Getting more Information

                  • Subroutines and Functions in Different Libraries

Tài liệu cùng người dùng

Tài liệu liên quan