Page 1 of 1

[Solved] Writer: insert paragraphs with text sequential

Posted: Sun Feb 05, 2012 7:42 pm
by franc
Hello

I want to create a new text document and fill in text from cells from a calc table.
It is a calc-document with just four cols, but about 15.000 rows containing japanese Signs (coded with utf8 I think) in one col.

I want to fill the text document sequential paragraph by paragraph with content (strings) e.g.:

First paragraph:
Fill one new paragraph1 with StringA, then fill StringB, then fill StringC.
Second paragraph:
Fill one new paragraph2 with StringD, then fill StringE, then fill StringF.
Third paragraph:
Fill one new paragraph3 with ...
...
Nth paragraph:
Fill paragraphN with String N, then fill StringN+1, then fill StringN+2

My question: how can I set the cursor just to the last position, after the last input?
I hope this is not already asked a billion times here but I didn't find.

Regard frank

Re: Insert paragraphs with text sequential into a text docum

Posted: Sun Feb 05, 2012 10:48 pm
by FJCC
This macro moves a text cursor to the end of a document and inserts two paragraphs with boring text.

Code: Select all

oText = ThisComponent.Text
oCurs = oText.createTextCursor()
oCurs.gotoEnd(False) 'False means the cursor does not expand during the move
oCurs.setString("FirstString ")
oCurs.gotoEnd(False)
oCurs.setString("SecondString ")
oCurs.gotoEnd(False)
oCurs.setString("ThirdString")
oCurs.gotoEnd(False)
oText.insertControlCharacter(oCurs.End,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
oCurs.gotoEnd(False)
oCurs.setString("FirstString ")
oCurs.gotoEnd(False)
oCurs.setString("SecondString ")
oCurs.gotoEnd(False)
oCurs.setString("ThirdString")
Of course, you could simplify this to a single setString() for each paragraph by writing

Code: Select all

oCurs.setString("FirstString SecondString ThirdString")

Re: Insert paragraphs with text sequential into a text docum

Posted: Mon Feb 06, 2012 1:15 am
by franc
Thank you, it was the method "gotoEnd" what I didn't know, as I am at the beginning of StarBasic.

EDIT: ...and the:

Doc.Text.insertControlCharacter(myCursor.End,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)