LibreOffice 宏 mac 通过下划线查找和替换空格错误

LibreOffice Macro mac find and replace spaces by underscore bug

我想在 libreoffice 中创建一个快捷方式来用下划线替换空格。

我录制了一个宏

我执行了简单的查找和替换。

但每次我尝试 运行 宏 libreoffice 退出 ;(

这是代码

REM  *****  BASIC  *****

sub replacespaces
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(17) as new com.sun.star.beans.PropertyValue
args1(0).Name = "SearchItem.StyleFamily"
args1(0).Value = 2
args1(1).Name = "SearchItem.CellType"
args1(1).Value = 0
args1(2).Name = "SearchItem.RowDirection"
args1(2).Value = true
args1(3).Name = "SearchItem.AllTables"
args1(3).Value = false
args1(4).Name = "SearchItem.Backward"
args1(4).Value = false
args1(5).Name = "SearchItem.Pattern"
args1(5).Value = false
args1(6).Name = "SearchItem.Content"
args1(6).Value = false
args1(7).Name = "SearchItem.AsianOptions"
args1(7).Value = false
args1(8).Name = "SearchItem.AlgorithmType"
args1(8).Value = 1
args1(9).Name = "SearchItem.SearchFlags"
args1(9).Value = 71680
args1(10).Name = "SearchItem.SearchString"
args1(10).Value = " "
args1(11).Name = "SearchItem.ReplaceString"
args1(11).Value = "_"
args1(12).Name = "SearchItem.Locale"
args1(12).Value = 255
args1(13).Name = "SearchItem.ChangedChars"
args1(13).Value = 2
args1(14).Name = "SearchItem.DeletedChars"
args1(14).Value = 2
args1(15).Name = "SearchItem.InsertedChars"
args1(15).Value = 2
args1(16).Name = "SearchItem.TransliterateFlags"
args1(16).Value = 1280
args1(17).Name = "SearchItem.Command"
args1(17).Value = 3

dispatcher.executeDispatch(document, ".uno:ExecuteSearch", "", 0, args1())

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:SearchResultsDialog", "", 0, Array())


end sub

谁能告诉我怎么了?

openoffice 和libreoffice 的宏记录器确实不如Microsoft Office 的有用。我建议不要使用它。使用像 XRAY (https://wiki.documentfoundation.org/Macros) for examining the objects you have found using the methods of the API. At first examine thisComponent. Doing so, with Calc, you will find a model which has multiple models of sheets which each implements an interface XReplaceable (http://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1util_1_1XReplaceable.html).

这样的工具来代替录制宏

示例:

Sub findAndReplace()
 oModel = thisComponent ' at first examine thisComponent
 ' xray oModel
 oSpreadSheet = oModel.getCurrentController().getActiveSheet()
 ' oSpreadSheet = oModel.getSheets().getByIndex(0)
 ' xray oSpreadSheet
 xReplaceDescr = oSpreadSheet.createReplaceDescriptor()
 ' xray xReplaceDescr
 xReplaceDescr.SearchString = " "
 xReplaceDescr.ReplaceString = "_"
 lFound = oSpreadSheet.replaceAll(xReplaceDescr)
 ' xray lFound
 MsgBox lFound & " replacements done."
End Sub