Ask Your Question
0

cursor.gotonextsentence failing

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

owlbrudder gravatar image
edit retag flag offensive close merge delete

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
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 38 times

Last updated: Jan 14 '17