2013-04-13 56 views
0

有沒有人知道如何在PHP中使用Libreoffice中的函數如str_ireplace
我想用在我的細胞功能。PHP str_ireplace在libreoffice基本

str_ireplace(search - range of cells, replace - range of cells, text) 

或至少str_replace

回答

1

我做了非常簡單的功能

Function Str_ireplace(Search As Variant, Replace As Variant, Source As String) 

    Dim Result As String 
    Dim StartPos As Long 
    Dim CurrentPos As Long 
    Dim CurrentSearch As String 
    Dim CurrentReplace As String 

    Result = "" 

    For Row = Lbound(Search, 1) To Ubound(Search, 1) 
    For Col = LBound(Search, 2) To UBound(Search, 2) 
     StartPos = 1 
     CurrentPos = 1 
     CurrentSearch = Search(Row, Col) 
     CurrentReplace = Replace(Row, Col) 
     Result = "" 


     Do While CurrentPos <> 0 
      CurrentPos = InStr(StartPos, Source, CurrentSearch) 
      If CurrentPos <> 0 Then 
       Result = Result + Mid(Source, StartPos, _ 
       CurrentPos - StartPos) 
       Result = Result + CurrentReplace 
       StartPos = CurrentPos + Len(CurrentSearch) 
      Else 
       Result = Result + Mid(Source, StartPos, Len(Source)) 
      End If    ' Position <> 0 
     Loop 
     Source = Result 
    Next 
    Next 


    Str_ireplace = Result  
End Function 

我用這個作爲例子: http://wiki.openoffice.org/wiki/Documentation/BASIC_Guide/Strings_(Runtime_Library)

0

試試這個

語法

REPLACE( 「文本」 的位置,長度, 「NewText」)

文本參照文本其中一部分將被替換。

位置是指替換將開始的文本中的位置。

長度是要替換的文本中的字符數。

NewText指代替文字的文字。

=REPLACE("1234567";1;1;"444") returns "444234567". One character at position 1 is replaced by the complete NewText. 

https://help.libreoffice.org/Calc/Text_Functions#Example_13

SUBSTITUTE( 「文本」, 「SEARCHTEXT」; 「NewText」;發生)

= SUBSTITUTE(「123123123」;「3」;「abc」)返回12abc12abc12abc。

= SUBSTITUTE(「123123123」;「3」;「abc」; 2)返回12312abc123。

https://help.libreoffice.org/Calc/Text_Functions#SUBSTITUTE

+0

不能使用的搜索,並用這種方法替換值數組的數組。 – StanleyD