edragon General User

Joined: 02 Aug 2010 Posts: 18 Location: Sankt-Peterburg, Russia
|
Posted: Mon Aug 02, 2010 7:00 am Post subject: SOLVED - OOo Writer macro - insert a new blank paragraph? |
|
|
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 |
|
edragon General User

Joined: 02 Aug 2010 Posts: 18 Location: Sankt-Peterburg, Russia
|
Posted: Tue Aug 03, 2010 2:23 am Post subject: |
|
|
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
|
|
|