LibreOffice XParagraphCursor卡在空白行时 [英] LibreOffice XParagraphCursor stuck when blank line

查看:77
本文介绍了LibreOffice XParagraphCursor卡在空白行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在LibreOffice 5之前可以正常工作的代码,但是在LibreOffice 6(32位和64位)中,它停止了工作.

I have a code that was working perfectly fine until LibreOffice 5. But in LibreOffice 6 (both 32 and 64 bits) it stopped working.

public String getNextSentenceOO() {
    while (moreParagraphsOO) {
        while (moreSentencesOO) {
            xSentenceCursor.gotoEndOfSentence(true);
            textSentence = xSentenceCursor.getString();
            xTextViewCursor.gotoRange(xSentenceCursor.getStart(), false);
            xTextViewCursor.gotoRange(xSentenceCursor.getEnd(), true);
            if (!textSentence.equals("")) {
                return textSentence;
            }

            moreSentencesOO = xSentenceCursor.gotoNextSentence(false);

            if (xSentenceCursor.isEndOfSentence() && !xSentenceCursor.isStartOfSentence()){
                moreSentencesOO = false;
            }                
        }
        
        moreParagraphsOO = xParagraphCursor.gotoNextParagraph(false);
        moreSentencesOO = xSentenceCursor.gotoStartOfSentence(false);
    }
    return null;
}

当文档中存在空白行时,就会出现此问题.在这种情况下,说明:

The problem arises when a blank line exists in the document. In that case, the instruction:

moreParagraphsOO = xParagraphCursor.gotoNextParagraph(false);

不会使光标前进到下一段,而是将其保留在同一位置,因此该函数进入无限循环.有什么想法吗?

doesn't make the cursor advance to the next paragraph, it remains in the same place, so the function enters an infinite loop. Any ideas?

正如我所说,这在LibreOffice 4和5(即使在LO5的最新版本中)也可以正常工作.它在LO6中停止工作.

As I have said, this was working flawlessly in LibreOffice 4 and 5 (even in the last version of LO5). It stopped working in LO6.

推荐答案

而不是段落游标,而是枚举段落.来自 Andrew Pitonyak的宏文档的清单7.52:

Instead of a paragraph cursor, enumerate paragraphs. From Listing 7.52 of Andrew Pitonyak's Macro Document:

oParEnum = ThisComponent.getText().createEnumeration()
Do While oParEnum.hasMoreElements()
    oPar = oParEnum.nextElement()

此外,清单7.65中有一条注释可能与您的问题有关:

Also, there is a note in Listing 7.65 that may be relevant to your question:

REM In this example, I assume that there is text after
REM the text section. If there is not, then this is
REM an infinite loop. You had better verify that
REM gotoNextParagraph does not return False.
Do While NOT IsEmpty(oCurs.TextSection)
    oCurs.gotoNextParagraph(False)
Loop

这篇关于LibreOffice XParagraphCursor卡在空白行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆