如何使用OObasic在电子表格中查找文本?

时间:2013-05-04 19:20:18

标签: libreoffice openoffice-basic libreoffice-basic

在OpenOffice文档[1]上,我找到了一个替换示例。但我没有找到搜索示例。

Dim Doc As Object
Dim Sheet As Object
Dim ReplaceDescriptor As Object
Dim I As Integer

Doc = ThisComponent
Sheet = Doc.Sheets(0)

ReplaceDescriptor = Sheet.createReplaceDescriptor()
ReplaceDescriptor.SearchString = "is"
ReplaceDescriptor.ReplaceString = "was"
For I = 0 to Doc.Sheets.Count - 1
   Sheet = Doc.Sheets(I)
   Sheet.ReplaceAll(ReplaceDescriptor) 
Next I

更好:我在哪里可以找到列出范围/单元格可能方法的文档?

[1] http://wiki.openoffice.org/wiki/Documentation/BASIC_Guide/Editing_Spreadsheet_Documents

1 个答案:

答案 0 :(得分:0)

首先:https://wiki.openoffice.org/wiki/Extensions_development_basic是一个很好的起点。特别是XRAY工具非常有用。

以下代码显示了一个搜索示例:

Dim oDoc As Object
Dim oSheet As Object
Dim oSearchDescriptor As Object
Dim i As Integer

oDoc = ThisComponent
oSheet = oDoc.Sheets(0)

oSearchDescriptor = oSheet.createSearchDescriptor()
oSearchDescriptor.SearchString = "is"
For i = 0 to oDoc.Sheets.Count - 1
   oSheet = oDoc.Sheets(i)
   oResults = oSheet.findAll(oSearchDescriptor)
   'xray oResults
   if not isnull(oResults) then msgbox oResults.AbsoluteName
Next i

如果您安装了XRAY,则可以使用它检查每个对象,并且您可以访问相关的API文档。

问候

阿克塞尔