Alexej Kryukov wrote:
Hi,
in my projects I often have to iterate through text portions in
OOo Writer text documents. So, when trying to adapt my older programs
to OOo 2.0 I noticed the following strange problem. Let's take
for example the following macro (which basically does nothing,
just iterates through text portions in order to access their "String"
property):
Sub IteratePortions ()
oDoc = ThisComponent
oText = oDoc.Text
oEnum = oText.createEnumeration ()
Do While oEnum.hasMoreElements
oPara = oEnum.nextElement
oParaEnum = oPara.createEnumeration ()
Do While oParaEnum.hasMoreElements ()
oPortion = oParaEnum.nextElement
Select Case oPortion.TextPortionType
Case "Text"
oPortionCursor = oText.createTextCursorByRange (oPortion, 0)
sPortionString = oPortionCursor.getString ()
Case Else
End Select
Loop
Loop
End Sub
If you run this macro on a document which is long enough, you
may notice that each time getString() is called, a progress indicator
is shown for few time, with a label which says (if I managed
to make it out) "Exporting document".
There is no such effect, if I call the "getString()" method for the
portion itself (i. e. execute oPortion.getString ()), instead of
creating an intermediate text cursor. However, intermediate text
cursors are often needed to workaround other OOo bugs, even if
creating them doesn't look necessary :(
This "exporting" looks quite irritating, not only because it
significantly slows execution of my functions, but also because
it doesn't allow me to create my own status bar indicator (which
may be quite important for long operations). So, can anybody
explain, which sort of exporting is performed here, and how can
I avoid it?
If anyone cares, I have verified this behavior. I modified the macro a
bit so that it works on documents containing things such as TextTabels
without crashing...
Sub IteratePortions()
Dim oText
Dim oEnum
Dim oPara
Dim oParaEnum
Dim oPortion
Dim oPortionCursor
Dim sPortionString$
oText = ThisComponent.getText()
oEnum = oText.createEnumeration ()
Do While oEnum.hasMoreElements
oPara = oEnum.nextElement
If oPara.supportsService("com.sun.star.text.Paragraph") Then
oParaEnum = oPara.createEnumeration ()
Do While oParaEnum.hasMoreElements ()
oPortion = oParaEnum.nextElement
Select Case oPortion.TextPortionType
Case "Text"
'oPortionCursor = oText.createTextCursorByRange (oPortion, 0)
oPortionCursor = oText.createTextCursorByRange (oPortion)
sPortionString = oPortionCursor.getString ()
Case Else
End Select
Loop
End If
Loop
End Sub
--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
My Book: http://www.hentzenwerke.com/catalog/oome.htm
Info: http://www.pitonyak.org/oo.php
See Also: http://documentation.openoffice.org/HOW_TO/index.html
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]