OpenOffice.org BASIC Guide - OpenOffice.org wiki
OpenOffice.org BASIC Guide - OpenOffice.org wiki
OpenOffice.org BASIC Guide - OpenOffice.org wiki
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
The Structure of Text Documents<br />
' loop over all paragraph portions<br />
While Enum2.hasMoreElements<br />
TextPortion = Enum2.nextElement<br />
If TextPortion.CharWeight = com.sun.star.awt.FontWeight.BOLD THEN<br />
CurLine = CurLine & "" & TextPortion.String & ""<br />
Else<br />
CurLine = CurLine & TextPortion.String<br />
End If<br />
Wend<br />
' output the line<br />
CurLine = CurLine & ""<br />
Print #FileNo, CurLine<br />
End If<br />
Wend<br />
' write HTML footer<br />
Print #FileNo, ""<br />
Close #FileNo<br />
The basic structure of the example is oriented towards the examples for running though the paragraph portions of<br />
a text already discussed previously. The functions for writing the HTML file, as well as a test code that checks the<br />
font weight of the corresponding text portions and provides paragraph portions in bold type with a<br />
corresponding HTML tag, have been added.<br />
Default values for character and paragraph properties<br />
Direct formatting always takes priority over indirect formatting. In other words, formatting using templates is<br />
assigned a lower priority than direct formatting in a text.<br />
Establishing whether a section of a document has been directly or indirectly formatted is not easy. The symbol<br />
bars provided by <strong>OpenOffice</strong>.<strong>org</strong> show the common text properties such as font type, weight and size. However,<br />
whether the corresponding settings are based on template or direct formatting in the text is still unclear.<br />
<strong>OpenOffice</strong>.<strong>org</strong> Basic provides the getPropertyState method, with which programmers can check how a<br />
certain property was formatted. As a parameter, this takes the name of the property and returns a constant that<br />
provides information about the origin of the formatting. The following responses, which are defined in the<br />
com.sun.star.beans.PropertyState enumeration, are possible:<br />
com.sun.star.beans.PropertyState.DIRECT_VALUE<br />
the property is defined directly in the text (direct formatting)<br />
com.sun.star.beans.PropertyState.DEFAULT_VALUE<br />
the property is defined by a template (indirect formatting)<br />
com.sun.star.beans.PropertyState.AMBIGUOUS_VALUE<br />
the property is unclear. This status arises, for example, when querying the bold type property of a<br />
paragraph, which includes both words depicted in bold and words depicted in normal font.<br />
The following example shows how format properties can be edited in <strong>OpenOffice</strong>.<strong>org</strong>. It searches through a text<br />
for paragraph portions which have been depicted as bold type using direct formatting. If it encounters a<br />
corresponding paragraph portion, it deletes the direct formatting using the setPropertyToDefault method and<br />
assigns a MyBold character template to the corresponding paragraph portion.<br />
Dim Doc As Object<br />
Dim Enum1 As Object<br />
Dim Enum2 As Object<br />
Dim TextElement As Object<br />
Dim TextPortion As Object<br />
Doc = ThisComponent<br />
Enum1 = Doc.Text.createEnumeration<br />
' loop over all paragraphs<br />
While Enum1.hasMoreElements<br />
TextElement = Enum1.nextElement<br />
74 <strong>OpenOffice</strong>.<strong>org</strong> 3.2 <strong>BASIC</strong> <strong>Guide</strong> · March 2010