-1

想要阅读文件文件的信息。

Ex. doc.odt file
David
12.13
OO

我想编辑下面的信息

David --> DAVID
12.13 --> 12.14
OO    --> OpenO

并将列表编辑信息导出到文本文件

Ex. changes.txt file
DAVID
12.14
OpenO

我的问题:如果段落中有任何其他字符,它不会将编辑信息导出到文本文件。

我的代码1

Dim filesize As Integer
    Dim FlName As String
    Dim Descriptor As Object  
    Dim Found As Object      
    Dim FoundAll As Object 
    Dim i          
    Dim Doc As Object
    Dim Enum As Object
    Dim TextElement As Object

    Doc = ThisComponent
    Enum = Doc.Text.createEnumeration

    FlName = "C:\changes.txt"
    Descriptor = ThisComponent.createSearchDescriptor()
    filesize = FreeFile()

    FoundAll = ThisComponent.findAll(Descriptor)    

    Open FlName For Output As #filesize

           While Enum.hasMoreElements
             TextElement = Enum.nextElement
             If TextElement.supportsService("com.sun.star.text.Paragraph") Then

                TextElement.String = Replace(TextElement.String, "David", "DAVID")
                If  TextElement.String = "DAVID" Then
                     Print #filesize, "DAVID"
                End If

                TextElement.String = Replace(TextElement.String, "12.13", "12.14")
                If  TextElement.String = "12.14" Then
                     Print #filesize, "12.14"
                End If

                TextElement.String = Replace(TextElement.String, "OO", "OpenO")
                If  TextElement.String = "OpenO" Then
                     Print #filesize, "OpenO"
                End If

             End If
           Wend

    Close #filesize

我的代码2

Dim C As Object
Dim R As Object
Dim M As Object  
Dim Found As Object      
Dim FoundAll As Object    
Dim i          

C = ThisComponent.createSearchDescriptor()
R = ThisComponent.createSearchDescriptor()
M = ThisComponent.createSearchDescriptor()

C.SearchString = ("David")
R.SearchString = "12.13"
M.SearchString = "OO"

FoundAll = ThisComponent.findAll(Descriptor)
   For i = 0 to FoundAll.getCount()-1

   Found = FoundAll.getByIndex(i)

If Descriptor.SearchString = "David" Then
   Found.setString("DAVID")
End If

If Descriptor.SearchString = "12.13" Then
   Found.setString("12.14")
End If

If Descriptor.SearchString = "OO" Then
   Found.setString("OpenO")
End If
Next
4

1 回答 1

0

我的代码3(如何搜索 3 个单词?)

Dim Descriptor As Object  
Dim Found As Object      
Dim FoundAll As Object    
Dim i As Long

Descriptor = ThisComponent.createReplaceDescriptor()
Descriptor = ThisComponent.createSearchDescriptor()
Descriptor.SearchRegularExpression = True
Descriptor.SearchString = "David"
Descriptor.SearchString = "12.13"
Descriptor.SearchString = "OO"


FoundAll = ThisComponent.findAll(Descriptor)
For i = 0 to FoundAll.getCount()-1

Found = FoundAll.getByIndex(i)

If Descriptor.SearchString = "David" Then
Found.setString("DAVID")
End If

If Descriptor.SearchString = "12.13" Then
Found.setString("12.14")
End If

If Descriptor.SearchString = "OO" Then
Found.setString("OpenO")
End If
Next
于 2014-03-05T09:54:03.300 回答