OO-Snippets: Adding formatted Text

Commons

Keywordsfontname, fontcolor, fontfamily, font
LanguageooRexx
ApplicationWriter
AuthorsMatthias Prem (initial)
Supported Versions2.0.x  
Supported OSAll  
QuestionHow can I add formatted text?
Answer

Code-Snippet-Listing (snippet-source)

/* AddingFormattedText.rex */
/* Macro */
/* Text shall be underlined, Times New Roman, size 15 and bold */

/* get the script context, the XModel and the XTextDocument interface */
xScriptContext=uno.getScriptContext()

oDoc=xScriptContext~getDocument
xTextDoc=oDoc~XTextDocument

/* get the TextCursor from the interface's Text*/
xTextCursor=xTextDoc~getText~createTextCursor

/* setting the properties of the cursor using the XPropertySet interface */
CursorProperties=xTextCursor~XPropertySet
CursorProperties~setPropertyValue("CharFontName", "Times New Roman")
CursorProperties~setPropertyValue("CharWeight", box("float", bsf.getConstant("com.sun.star.awt.FontWeight", "BOLD"))) --Value is 150.0
CursorProperties~setPropertyValue("CharHeight", box("float", "15"))
CursorProperties~setPropertyValue("CharUnderline", box("short", bsf.getConstant("com.sun.star.awt.FontUnderline", "DOUBLE"))) --Value is 2

/* set text at the end of the document */
xTextDoc~getText~getEnd~setString("This is OORexx formatted text!")

::requires UNO.CLS

Changelog

DateUserModification
2006-07-06matthiaspremInitial version

and