[Solved] Writer: insert paragraphs with text sequential

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
franc
Posts: 21
Joined: Sat Oct 08, 2011 2:12 pm

[Solved] Writer: insert paragraphs with text sequential

Post 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
Last edited by franc on Mon Feb 06, 2012 1:14 am, edited 1 time in total.
OpenOffice 3.3
FJCC
Moderator
Posts: 9248
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Insert paragraphs with text sequential into a text docum

Post 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")
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
franc
Posts: 21
Joined: Sat Oct 08, 2011 2:12 pm

Re: Insert paragraphs with text sequential into a text docum

Post 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)
OpenOffice 3.3
Post Reply