首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何利用PyUNO与OpenOffice编写器获取文本坐标

如何利用PyUNO与OpenOffice编写器获取文本坐标
EN

Stack Overflow用户
提问于 2014-07-17 12:02:39
回答 1查看 328关注 0票数 1

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

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-17 14:05:50

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

代码语言:javascript
复制
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

希望这对你有帮助

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24803014

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档