簡體   English   中英

在Open / Libre / Neo Office中的文本選擇中查找段落的宏

[英]Macro to find paragraphs in text selection in Open/Libre/Neo Office

我正在嘗試枚舉用戶在(Neo | Libre | Open)Office中選擇的段落。

當我使用以下代碼時,請從此處修改版本,

Sub CheckForSelection
    Dim oDoc as Object
    Dim oText

    oDoc = ThisComponent
    oText = oDoc.Text

    if not IsAnythingSelected(oDoc) then
        msgbox("No text selected!")
        Exit Sub
    end if

    oSelections = oDoc.getCurrentSelection() 
    oSel = oSelections.getByIndex(0)    

    ' Info box
    'MsgBox oSel.getString(), 64, "Your Selection"

    oPE = oSel.Text.createEnumeration()
    nPars = 0
    Do While oPE.hasMoreElements()
        oPar = oPE.nextElement()
        REM The returned paragraph will be a paragraph or a text table
        If oPar.supportsService("com.sun.star.text.Paragraph") Then 
            nPars = nPars + 1
        ElseIf oPar.supportsService("com.sun.star.text.TextTable") Then 
            nTables = nTables + 1
        end if
    Loop

    ' Info box
    MsgBox "You selection has " & nPars & " paragraphs.", 64

end Sub

它可以找到文檔中的所有段落,而不僅是所選內容。 Google讓我失敗了。 關於如何在選擇中查找單個段落有什么想法?

oSel.Text為捷徑oSel.getText()其中“返回其中文本位置被包含在文本界面”。 https://www.openoffice.org/api/docs/common/ref/com/sun/star/text/XTextRange.html#getText

因此,僅從Selection獲取ParagraphEnumeration ,應使用oPE = oSel.createEnumeration()而不是oPE = oSel.Text.createEnumeration()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM