【问题标题】:LibreOffice XParagraphCursor stuck when blank lineLibreOffice 段落光标在空行时卡住
【发布时间】:2020-06-29 12:07:35
【问题描述】:

我的代码在 LibreOffice 5 之前运行良好。但在 LibreOffice 6(32 位和 64 位)中它停止工作。

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;
}

当文档中存在空行时会出现问题。在这种情况下,指令:

moreParagraphsOO = xParagraphCursor.gotoNextParagraph(false);

不使光标前进到下一段,它保持在同一个地方,所以函数进入一个无限循环。有什么想法吗?

正如我所说,这在 LibreOffice 4 和 5 中运行良好(即使在 LO5 的最新版本中也是如此)。它在 LO6 中停止工作。

【问题讨论】:

    标签: java libreoffice openoffice.org


    【解决方案1】:

    枚举段落而不是段落光标。来自Andrew Pitonyak's Macro Document 的代码清单 7.52:

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

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

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-19
      • 1970-01-01
      • 2021-09-18
      • 1970-01-01
      • 2013-05-16
      • 2023-02-09
      • 1970-01-01
      • 2015-11-20
      相关资源
      最近更新 更多