Language

The Free and Open Productivity Suite
Released: Apache OpenOffice 4.1.15

API

SDK

Tips ‘n’ Tricks

Miscellaneous

Code Snippets

This is a collection of code snippets collected mostly from questions and answers from the mailing list dev@api.openoffice.org.

Categories

We have already collected several code snippets and under the Code Snippet Base you can see the for what the snippets are good for!

How to Contribute

We strongly encourage everybody who asks a question on dev@api.openoffice.org and who gets sufficient answers to summarize the answers either with the snippet creator or manually in the following template and send the xml code snippet (DTD for validation) to dev@api.openoffice.org:

<!-- 
    CodeSnippet DTD
-->
<!ELEMENT snippet ( keywords, authors, versions?, operating-systems?, question, answer, changelog ) >
<!ATTLIST snippet
            language [1] ( OOBasic|Java|Cpp|Python|OLE )              #REQUIRED
            application [2] ( Writer|Calc|Impress|Draw|Office|Database ) #REQUIRED >


<!--
    Put as many sensible keywords into this secion as possible, each keyword in a separate element.
-->
<!ELEMENT keywords [3] ( keyword+ ) >
<!ELEMENT keyword (#PCDATA)>


<!--
        List the initial writers in this form (with initial="true"). Initial Writers is a term from the PDL (License). 
        If one of these authors assined copyright to somebody else, e.g. the company they are working for, use the attribute copyright="..." 
        and name the copyright holder.
-->
<!ELEMENT authors ( author+ ) > [4]
<!ELEMENT author (#PCDATA)>
<!ATTLIST author 
            id [5] ID #REQUIRED
            initial [6] CDATA #IMPLIED
            email [7] CDATA #REQUIRED
            copyright [8] CDATA #IMPLIED>

<!--
        Put the part of the question which should be part of the overview index, as a direct child of the ... 
        element. For further explanation you can use child elements, like 

...

. --> <!ELEMENT question [9] (#PCDATA|p|listing)*> <!ATTLIST question heading [10] CDATA #REQUIRED> <!-- The answer to the question --> <!ELEMENT answer [11] ( p|listing )+> <!-- The answer in english --> <!ELEMENT p ( #PCDATA|a|b|ul|code )*> <!ELEMENT listing [12] ( #PCDATA )* > <!-- The changelog holds all changes made to the snippet including the initial release --> <!ELEMENT changelog ( change+ )> <!-- The change itself --> <!ELEMENT change [13] ( #PCDATA ) > <!ATTLIST change author-id [14] IDREF #REQUIRED date [15] CDATA #REQUIRED> <!-- a link to an external resource --> <!ELEMENT a (#PCDATA)> <!ATTLIST a href CDATA #REQUIRED> <!ELEMENT versions (version+)> <!ELEMENT version [16] EMPTY> <!ATTLIST version number [17] CDATA #REQUIRED status [18] (tested|untested|may_work|can_not_work)> <!ELEMENT operating-systems (operating-system+)> <!ATTLIST operating-system name [19] (Win32|Linux|Solaris|MacOSX|All)> <!-- make something bold --> <!ELEMENT b (#PCDATA)> <!ELEMENT ul (li+)> <!ELEMENT li (#PCDATA)> <!ELEMENT code (#PCDATA)>

[1] - Programming Language
Name the programming language which is used for this code snipped, here. E.g. "OOBasic", "Java", "Cpp", "Python", ...
[2] - Application
Name the OOo application to which the code snippet applies, here. E.g. "Writer", "Calc", "Impress", "Draw", "Office", "Database". Use "Office" if it is generic.
[3] - Keywords
Put as many sensible keywords into this section as possible, each keyword in a separate element.
[4] - List of authors/contributors
Use for each author/contributor a separatr element.
[5] - Id
Use your OpenOffice user name here.
[6] - Initial
List the initial writers in this form (with initial="true"). Initial Writers is a term from the PDL (License). If one of these authors assigned copyright to somebody else, e.g. the company they are working for, use the attribute copyright="... " and name the copyright holder.
[7] - Email
Use your email address here.
[8] - Copyright
Insert here your copyright if necessary.
[9] - Question
Put the part of the question which should be part of the overview index, as a direct child of the <question>...</question> element. For further explanation you can use child elements, like <p>...</p> or <listing>...</listing>.
[10] - Heading
Insert a short heading (abstract) here to identify the snippet (e.g. in the navigation overview).
[11] - Answer
Put the answer below this tag enclosed into <p>...</p>. You could use as many <p>'s as you want, nesting of <p>-Tags is not allowed.
[12] - Code Listing
Use <listing>...</listing> for your code listing itself. This tag will include <pre>, thus line breaks in the source will be interpreted as such.
[13] - Change
Use this element to show changes.
[14] - Author-id
The ID of the author who has mamde the change.
[15] - Date
The date of the change.
[16] - Version
Use one or more version elements to show history.
[17] - Number
Used for the verison number
[18] - Status
Used to show the status of this version. Valid entires are "tested", "untested", "may_work", "can_not_work"
[20] - Platform
Used to idnetiy the platform. Ideally the snippet contains no platform specific code. Valid platforms are "Win32", "Linux", "Solaris", "MacOSX", "All".

Open-Source-Software is free as in free speech, not necessary free as in free beer. Thus, please pay those community members who answer your questions by contributing the summary. If most community members support this system of collecting code snippets, we soon will have a great collection of such.

Of course, if you answer a question, you are welcome to use the template as well.

Apache Software Foundation

Copyright & License | Privacy | Contact Us | Donate | Thanks

Apache, OpenOffice, OpenOffice.org and the seagull logo are registered trademarks of The Apache Software Foundation. The Apache feather logo is a trademark of The Apache Software Foundation. Other names appearing on the site may be trademarks of their respective owners.