2014-07-17 24 views
0

我有一個python腳本,它成功地使用PyUNO在OpenOffice Writer文檔中進行搜索和替換。我想問如何獲得找到的文本的座標?如何用OpenOffice編寫器使用PyUNO獲取文本座標

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 
+0

你所說的「座標」意思? 文檔在文檔中的位置取決於頁面/字符大小和其他事實(屏幕/打印分辨率)。 你想用這樣的值做什麼? – ngulam

+0

目的問題是我想在odt文件中添加一個'指定'文本,並檢測這個文本的頁面大小調整位置。 – Randy

回答

0

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

希望這有助於你

+0

它的工作,非常感謝! – Randy

相關問題