OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

SOLVED - OOo Writer macro - insert a new blank paragraph?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
edragon
General User
General User


Joined: 02 Aug 2010
Posts: 18
Location: Sankt-Peterburg, Russia

PostPosted: Mon Aug 02, 2010 7:00 am    Post subject: SOLVED - OOo Writer macro - insert a new blank paragraph? Reply with quote

Hi all,

I need to insert an empty line (really, a paragraph) after each normal text paragraph (not empty). Firstly I used this code:

Code:

Sub insertCarriageRet(doc)
   eNumDoc = doc.getText().createEnumeration()
   etext = doc.getText()
   While eNumDoc.hasMoreElements
      textPar = eNumDoc.nextElement
      If textPar.supportsService("com.sun.star.text.Paragraph") Then
         if len(textPar.getString()) > 0 then
            textPar.String = textPar.getString() & CHR$(13)
         end if
      End If   
   Wend   
End Sub


but it eliminates formatting of the paragraph - all lower and upper indexes, for example.

So I tried this thing:

Code:

Sub insertCarriageRet(doc)
   etext = doc.getText()
   tcur = etext.createTextCursor()
   tcur.gotoStart(true)
   While tcur.gotoNextParagraph(true)
      if Len(tcur.getString()) > 0 then
         etext.insertString(tcur.getEnd(), CHR$(13), false)
      end if
   Wend
End Sub


But it fails on large documents (about 150 pages) - first 35 pages are processed normally, then no more paragraphs are inserted without any error message (cursor breakes?), and procedure finishes as if nothing bad happened.

Find and Replace using RegExps something like "\x000d" with "\x000d\x000d" found nothing, and CHR$(13) with CHR$(13) & CHR$(13) as well.

Finally, I tried to play with ".uno:InsertPara", but have no idea how to get into the right place.

Maybe the first sub is the best approach - but how to insert this "CR" accurately?


Last edited by edragon on Tue Aug 03, 2010 2:24 am; edited 1 time in total
Back to top
View user's profile Send private message
edragon
General User
General User


Joined: 02 Aug 2010
Posts: 18
Location: Sankt-Peterburg, Russia

PostPosted: Tue Aug 03, 2010 2:23 am    Post subject: Reply with quote

Thanks all for your kind attention. Here is my solution:

Code:

Sub insertCarriageRet(doc)
   eNumDoc = doc.getText().createEnumeration()
   etext = doc.getText()
   While eNumDoc.hasMoreElements
      textPar = eNumDoc.nextElement
      If textPar.supportsService("com.sun.star.text.Paragraph") Then
         if len(textPar.getString()) > 0 then
            etext.insertString(textPar.getEnd(), CHR$(13), false)
         end if
      End If   
   Wend
End Sub
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group