I need to write a Writer macro to sort a selection with comma-separated numbers. For example, transform this
10, 23, 2, 109, 55
into this
2, 10, 23, 55, 109
I try to do it this way:
- Convert text into table
- Select table
- Table sort by columns
- Convert table into text
But the macro I’ve recorded always ask me sorting parameters, and the macro breaks in point 3 with the message “I can’t order the selection”
The macro code:
sub sorting
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(4) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Delimiter"
args1(0).Value = ","
args1(1).Name = "WithHeader"
args1(1).Value = false
args1(2).Name = "RepeatHeaderLines"
args1(2).Value = 0
args1(3).Name = "WithBorder"
args1(3).Value = true
args1(4).Name = "DontSplitTable"
args1(4).Value = false
dispatcher.executeDispatch(document, ".uno:ConvertTextToTable", "", 0, args1())
rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:ConvertTextToTable", "", 0, Array())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:SelectTable", "", 0, Array())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:TableSort", "", 0, Array())
rem ----------------------------------------------------------------------
dim args5(0) as new com.sun.star.beans.PropertyValue
args5(0).Name = "Delimiter"
args5(0).Value = ","
dispatcher.executeDispatch(document, ".uno:ConvertTableToText", "", 0, args5())
rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:ConvertTableToText", "", 0, Array())
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:GoToStartOfLine", "", 0, Array())
rem ----------------------------------------------------------------------
dim args8(1) as new com.sun.star.beans.PropertyValue
args8(0).Name = "Count"
args8(0).Value = 1
args8(1).Name = "Select"
args8(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args8())
rem ----------------------------------------------------------------------
dim args9(1) as new com.sun.star.beans.PropertyValue
args9(0).Name = "Count"
args9(0).Value = 1
args9(1).Name = "Select"
args9(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoUp", "", 0, args9())
end sub
Any ideas?