<p>The example programs are embedded in StarOffice/OpenOffice.org documents
in the samples directory.<br>
To view or edit the StarOffice/OpenOffice.org Basic source, select the
appropriate document and then select Tools->Macro.</p>
<p> Most of the examples are stand-alone, but two of them (Creating an Index
and Import/Export of ASCII Files) have an associated data file identified
by a .txt file name suffix).</p>
<p>These examples are taken from the Programmer's Tutorial. Some of them
were ported to Java and you find them above.</p>
<p>These examples are presented in the order in which they appear in Chapter
5.</p>
<tablewidth="94%"border="1">
<tr>
<tdwidth="24%"><b>Example</b></td>
<tdwidth="76%"><b>Description</b></td>
</tr>
<tr>
<tdwidth="24%"><ahref="http://api.openoffice.org/source/browse/api/odk/examples/basic/text/modifying_text_automatically/"target="_blank"><fontface="Times New Roman, serif">Changing
Appearance</font></a></td>
<tdwidth="76%">To change the style used for certain words, you can
start with the following example. This code searches for the regular
which stands for the text portion the followed by exactly one lowercase
letter. All occurrences of these four letters are then changed to
be displayed in bold characters. The same happens in the next part
of the program, this time changing the appearance of <fontface="Courier New, Courier, mono">all[a-z]</font>
to italic. In order for this example to work, you must execute it
from an open text document.</td>
</tr>
<tr>
<tdwidth="24%"><ahref="http://api.openoffice.org/source/browse/api/odk/examples/basic/text/modifying_text_automatically/"target="_blank"><fontface="Times New Roman, serif">Replacing
Text</font></a></td>
<tdwidth="76%">
<p>If you regularly receive documents from other people for editing,
you might want to make sure that certain words are always written
the same. The next example<br>
illustrates this by forcing certain words to be spelled in American
English.<br>
In order for this example to work, you must execute it from an open
text document. For a real world application, you’d probably
want to read the words from an external file.</p>
</td>
</tr>
<tr>
<tdwidth="24%"><ahref="http://api.openoffice.org/source/browse/api/odk/examples/basic/text/modifying_text_automatically/"target="_blank"><fontface="Times New Roman, serif">Using
Regular Expressions</font></a></td>
<tdwidth="76%">
<p>Another application of automatic text modification is related to
stylistic questions. Suppose your company’s policy is to avoid
the use of certain words. You want to replace these words, but you
can’t do that automatically, because you have to find the appropriate
replacement which depends on the context. So instead of deleting
or replacing the offending words automatically, you change their
color to make them stand out during a subsequent manual review process.<br>
The following example handles two kinds of unwanted wordings: those
which are absolutely forbidden and must be replaced by something
else, and those which are considered bad style. A subroutine is
responsible for the changes. It can be used to make all words in
a list appear in a certain color in the text document. To keep the
lists short, we are using regular expressions here which provide
for the variants of the words (plural, adjective etc.).</p>
</td>
</tr>
<tr>
<tdwidth="24%"><ahref="http://api.openoffice.org/source/browse/api/odk/examples/basic/text/modifying_text_automatically/"target="_blank"><fontface="Times New Roman, serif">Inserting
Bookmarks</font></a></td>
<tdwidth="76%">
<p>The next example does something very similar. This time, however,
we do not<br>
change the color of the words but insert a bookmark at each of them.
You can thus use the StarOffice navigator to jump directly from
word to word. Bookmarks have first to be created using <fontface="Courier New, Courier, mono">createInstance()</font>.
They are then inserted with <fontface="Courier New, Courier, mono">insertTextContent()</font>
at the current text range.</p>
<p>The main difference to the preceding example is the For loop in
of changing the color of the current word, it creates a new bookmark,
oBookmark, whose name is the current word with an integer appended.
It then<br>
inserts this bookmark at the word.</p>
</td>
</tr>
<tr>
<tdwidth="24%"><ahref="http://api.openoffice.org/source/browse/api/odk/examples/basic/text/creating_an_index/"target="_blank"><fontface="Times New Roman, serif">Creating
an Index</font></a></td>
<tdwidth="76%">Indices for text documents can be created manually in
StarWriter by clicking on the words that shall appear in the index.
If the document is large or if you have to generate indices for several
documents, this task should be automated.</td>
</tr>
<tr>
<tdwidth="24%"><ahref="http://api.openoffice.org/source/browse/api/odk/examples/basic/sheet/"target="_blank"><fontface="Times New Roman, serif">Adapting
to Euroland</font></a></td>
<tdwidth="76%">Most of the member of the European Union will abandon
their old currency in favor of the new Euro in 2001. This requires
modifications to all programs using the old currencies. Since the
exchange rates for the old currencies have been fixed at the end of
1999, one can already convert old data. The following program does
this for all values in a table that are formatted with the currency
string DM.</td>
</tr>
<tr>
<tdwidth="24%"><ahref="http://api.openoffice.org/source/browse/api/odk/examples/basic/drawing/"target="_blank"><fontface="Times New Roman, serif">Import/Export
of ASCII Files</font></a></td>
<tdwidth="76%">You can use the drawing facilities of StarOffice API
to generate a picture from ASCII input. One application would be a
hierarchical representation of a directory listing, based on textual
data.</td>
</tr>
<tr>
<tdwidth="24%"><ahref="http://api.openoffice.org/source/browse/api/odk/examples/basic/stock_quotes_updater/"target="_blank"><fontface="Times New Roman, serif">Stock
Quotes Updater</font></a></td>
<tdwidth="76%">If you want to display stock charts for certain companies,
you can fire up your browser every day, go to Yahoo, look up the quote
and copy it by hand into a table. Or you can use a program that does
all this automatically. The following example relies on the sheet
module. It uses URLs to obtain the current stock quotes. The quotes
are displayed in sheets, one for each company. We show a line diagram
and the numerical values for this company on every sheet. The functionality
is hidden in the three subroutines <fontface="Courier New, Courier, mono">GetValue()</font>,
<fontface="Courier New, Courier, mono">UpdateValue()</font>, and
<tdwidth="24%"><ahref="http://api.openoffice.org/source/browse/api/odk/examples/basic/forms_and_controls/"target="_blank"><fontface="Times New Roman, serif">Forms
and Controls</font></a></td>
<tdwidth="76%">The example document Burger Factory offers you some
forms and controls, which you can use to order your desired burger
type, beverage, topping, and sauce. By hitting the button "Order