1

我有一个 python 脚本,可以使用 PyUNO 在 OpenOffice Writer 文档中成功进行搜索和替换。我想问如何获取找到的文本的坐标?

import string
search = document.createSearchDescriptor()
search.SearchString = unicode('find')
#search.SearchCaseSensitive = True
#search.SearchWords = True
found = document.findFirst(search)
if found:
    #log.debug('Found %s' % find)
    ## any code here help to get the coordinate of found text?
    pass
4

1 回答 1

1

这是一些 StarBASIC 代码,用于在 Writer 文档中查找搜索表达式的页码:

SUB find_page_number()

oDoc = ThisComponent
oViewCursor = oDoc.getCurrentController().getViewCursor()
oSearchFor = "My Search example"

oSearch = oDoc.createSearchDescriptor()
With oSearch
   .SearchRegularExpression = False
   .SearchBackwards = False
   .setSearchString(oSearchFor)
End With

oFirstFind = oDoc.findFirst(oSearch)


If NOT isNull(oFirstFind) Then
    oViewCursor.gotoRange(oFirstFind, False)
    MsgBox oViewCursor.getPage()
Else
   msgbox "not found: " & oSearchFor
End If

希望这可以帮助你

于 2014-07-17T14:05:50.853 回答