Useful Macro Information
For OpenOffice.org
By
Andrew Pitonyak
This is not the same as my book
OpenOffice.org Macros Explained.
My book is a more organized presentation. This
document, is primarily a random collection of
thoughts and examples (brain dump).
Last Modified
Tuesday, January 6, 2009 at 02:13:33 AM
Document Revision: 1074
Thank You
Thanks to my wife Michelle Pitonyak for supporting and encouraging me to write this
document. Thank you Laurent Godard (and the French translation team) for your good ideas
and hard work. Thanks to Hermann-Josef Beckers for his German translation. Kelvin
Eldridge, you have great understanding and have helped me understand numerous bugs. Jean
Hollis Weber and Solveig Haugland, thank you for the personal replies when I had specific
document usage problems. Sasa Kelecevic, and Hermann Kienlein, you have provided many
working examples to help me. Andreas Bregas, thank you for the quick replies, descriptions,
and fixes. Mathias Bauer, thank you for the explanations and examples revealing the deep
mysteries of the internals. I owe a large thank you to the entire open-source community and
the mailing lists for providing helpful information and support. Finally, I should thank Jean
Hollis Weber and C Robert Pearsall for agreeing to be technical editors for my book due for
publication in August of 2004. Thanks to Christian Junker, for reviewing and making
extensive changes and additions to the document – Christian spent numerous hours
proofreading and providing updates.
Disclaimer
The material in this document carries no guarantee of applicability, accuracy, or safety. Use
the information and macros in this document at your own risk. In the unlikely event that they
cause the loss of some or all of your data and/or computer hardware, that neither I, nor any of
the contributors, will be held responsible.
Contact Information
Andrew Pitonyak • 6888 Bowerman Street West • Worthington, OH 43085 • USA
home: andrew@pitonyak.org • work:
home telephone: 614-438-0190 • cell telephone: 614-937-4641
Credentials
I have two Bachelors of Science degrees, one in Computer Science and one in Mathematics. I
also have two Masters of Science degrees, one in Applied Industrial Mathematics and one in
Computer Science. I have spent time at Oakland University in Rochester Michigan, The Ohio
State University in Columbus Ohio, and at The Technical University Of Dresden in Dresden
Germany.
Public Documentation License Notice
The contents of this Documentation are subject to the Public Documentation License Version
1.0 (the "License"); you may only use this Documentation if you comply with the terms of
this License.
A copy of the License is available at http://www.openoffice.org/licenses/pdl.pdf
The Original Documentation is http:// www.pitonyak.org /AndrewMacro.odt
Contribution Contributor Contact Copyright
Original author Andrew Pitonyak andrew@pitonyak.org 2002-2008
French translation
The French Native-lang
documentation project
doc@fr.openoffice.org 2003
German Translation Hermann-Josef Beckers hjb-rheine@t-online.de 2003
Macros Hermann Kienlein info@kienlein.com 2002-2003
Macros Sasa Kelecevic scat@teol.net 2002-2003
Editing and additions Christian Junker usboy2004@web.de 2004
iii
Table of Contents
Thank You.................................................................................................................................2
Disclaimer..................................................................................................................................2
Contact Information...................................................................................................................2
Credentials.................................................................................................................................2
Public Documentation License Notice.....................................................................................iii
Table of Contents......................................................................................................................iv
1. Introduction...........................................................................................................................1
1.1. Change history..............................................................................................................1
1.2. Abbreviations and definitions.......................................................................................1
2. Available Resources..............................................................................................................3
2.1. Included Material..........................................................................................................3
2.2. On line Resources..........................................................................................................3
2.3. Translations of this document.......................................................................................4
3. Getting started: concepts.......................................................................................................7
3.1. My first macro: “Hello World”.....................................................................................7
3.2. Grouping Code..............................................................................................................7
3.3. Debugging.....................................................................................................................9
3.4. Variables........................................................................................................................9
3.5. Accessing And Creating Objects In OpenOffice..........................................................9
3.6. Everyone keeps talking about UNO, what is it?.........................................................10
3.6.1. Simple types........................................................................................................10
3.6.2. Object..................................................................................................................11
3.6.3. Structures.............................................................................................................11
3.6.4. Interfaces.............................................................................................................11
3.6.5. Services................................................................................................................12
3.6.6. Interfaces and services.........................................................................................13
3.6.7. What type is this object?......................................................................................13
3.6.8. What methods, properties, interfaces, and services are supported?................16
3.6.9. Languages other than Basic.................................................................................16
3.6.9.1. CreateUnoService........................................................................................16
3.6.9.2. ThisComponent............................................................................................17
3.6.9.3. StarDesktop......................................................................................................17
3.6.10. Accessing methods and properties................................................................18
3.7. Summary.....................................................................................................................18
4. Examples.............................................................................................................................21
4.1. Debugging And Inspecting Macros.............................................................................21
4.1.1. Determine Document Type.................................................................................21
4.2. X-Ray..........................................................................................................................22
iv
4.3. Dispatch: Using Universal Network Objects (UNO)..................................................23
4.3.1. The dispatcher requires a user interface..............................................................23
4.3.1.1. Modifying the menu – a dispatcher example...............................................24
4.4. Intercept menu commands using Basic.......................................................................25
5. Miscellaneous Examples.....................................................................................................29
5.1. Display Text In Status Bar..........................................................................................29
5.2. Display All Styles In The Current Document.............................................................29
5.3. Iterate Through All Open Documents.........................................................................30
5.4. List Fonts And Other Screen Information...................................................................30
5.4.1. Display supported fonts.......................................................................................31
5.5. Set the default font using the ConfigurationProvider..................................................32
5.6. Print Current Document..............................................................................................32
5.6.1. Print Current Page...............................................................................................33
5.6.2. Other Printing Arguments...................................................................................34
5.6.3. Landscape............................................................................................................34
5.7. Configuration information..........................................................................................34
5.7.1. OOo version.........................................................................................................34
5.7.2. OOo Locale.........................................................................................................35
5.8. Open And Close Documents (And The Desktop).......................................................35
5.8.1. Close OpenOffice And/Or Documents................................................................35
5.8.1.1. What if the file is modified?........................................................................36
5.8.2. Load A Document From A URL.........................................................................37
5.8.2.1. A complete example....................................................................................38
5.8.3. Save a document with a password.......................................................................40
5.8.4. Create a new document from a template.............................................................40
5.8.5. How do I Enable Macros With LoadComponentFromURL...............................40
5.8.6. Error handling on load.........................................................................................41
5.8.7. Mail Merge example, merge all documents in a directory..................................42
5.9. Loading/Inserting a graphic into your document........................................................43
5.9.1. Danny Brewer embeds a graphic.........................................................................45
5.9.2. Embed a graphics using a dispatch......................................................................46
5.9.3. Embed a graphics directly...................................................................................46
5.9.4. Duplicate an existing graphic..............................................................................47
5.9.5. Convert all linked graphics..................................................................................47
5.9.6. Access OOo's internal storage system.................................................................49
5.10. Setting Margins.........................................................................................................50
5.10.1. Setting the paper size.........................................................................................50
5.11. Calling an external program (Internet Explorer) using OLE....................................51
5.12. Use the Shell command for files containing spaces..................................................51
5.13. Read And Write Number In File ..............................................................................52
v
- 1
- 2
前往页