Ask Your Question
0

cursor.gotonextsentence failing [closed]

asked 2017-01-14 05:39:27 +0200

owlbrudder gravatar image

updated 2020-09-20 23:10:45 +0200

Alex Kemp gravatar image
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-09-20 23:11:03.428614

Comments

I forgot to mention I am running LibreOffice 5.2.3.3

owlbrudder gravatar imageowlbrudder ( 2017-01-14 05:43:54 +0200 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2017-01-14 12:04:09 +0200

karolus gravatar image

updated 2017-01-14 13:00:07 +0200

It seems the .gotoNextSentence(False) method does not return False at the End of Document.

Here a solution in python for counting Sentences and Paragraphs.

def count_Paras_and_sentences():
    doc = XSCRIPTCONTEXT.getDocument()
    cursor = doc.Text.createTextCursor()
    cursor.gotoStart(False)
    sentencecount = 0
    paracount = 0
    while True:
        sentencecount += 1
        cursor.gotoNextSentence( False )
        cursor.gotoEndOfSentence( False )
        if cursor.isEndOfParagraph():
            paracount += 1
            if not cursor.gotoNextParagraph( False ):
                return paracount, sentencecount

Edit: the same more pythonic-Style:

def count_Sentences(cursor, count=0):
    while not cursor.isEndOfParagraph():
        count += 1
        cursor.gotoNextSentence( False )
        cursor.gotoEndOfSentence( False )
    return count




def count_Paras_and_sentences():    
    doc = XSCRIPTCONTEXT.getDocument()
    cursor = doc.Text.createTextCursor()
    cursor.gotoStart(False)
    sentencecount = 0
    paracount = 0
    while cursor.gotoNextParagraph(False):
        sentencecount += count_Sentences(cursor, sentencecount)
        paracount += 1

    return paracount, sentencecount
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-01-14 05:39:27 +0200

Seen: 62 times

Last updated: Jan 14 '17