I'm not certain where to post this so (as is usually the case with me) move it where it belongs.

Edit: Tested and modified with Libreoffice 4.4.4 |
Code: Select all
sub FormatProductDescription
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
dim args1(0) as new com.sun.star.beans.PropertyValue
dim args2(0) as new com.sun.star.beans.PropertyValue
dim args3(0) as new com.sun.star.beans.PropertyValue
dim args4(1) as new com.sun.star.beans.PropertyValue
dim PositionOfEnter as Long
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----RESET FORMAT TO DEFAULT STYLE
dispatcher.executeDispatch(document, ".uno:ResetAttributes", "", 0, Array())
rem ----APPLY FORMAT
oCell = ThisComponent.getCurrentSelection()
TextContent = oCell.string
PositionOfEnter = InStr(TextContent, chr(10))
if PositionOfEnter > 0 then
args1(0).Name = "Symbols"
args2(0).Name = "FontHeight.Height"
args2(0).Value = 10
args3(0).Name = "Italic"
args3(0).Value = true
args1(0).Value = Left(TextContent, PositionOfEnter)
dispatcher.executeDispatch(document, ".uno:InsertSymbol", "", 0, args1())
dispatcher.executeDispatch(document, ".uno:FontHeight", "", 0, args2())
dispatcher.executeDispatch(document, ".uno:Italic", "", 0, args3())
args1(0).Value = Mid(TextContent, PositionOfEnter)
dispatcher.executeDispatch(document, ".uno:InsertSymbol", "", 0, args1())
end if
args4(0).Name = "By"
args4(0).Value = 1
args4(1).Name = "Sel"
args4(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoDown", "", 0, args4())
end sub