[英]How to get Text coordinates using PyUNO with OpenOffice writer
I have a python script that successfully does a search and replace in an OpenOffice Writer document using PyUNO. 我有一个python脚本,可以使用PyUNO成功地进行搜索并替换OpenOffice Writer文档。 I wanna to ask how to get the coordinate of found text?
我想问一下如何获取找到的文本的坐标?
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
This is some StarBASIC code to find the page number of a search expression in a Writer document: 这是一些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
Hope this helps you 希望这对您有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.