如何获得文本坐标使用PyUNO与OpenOffice作家



我有一个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

这是一些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

希望这对你有帮助

最新更新