OO-Snippets: adjust table cell text to the right

Commons

Keywordsadjust cell text, table
LanguageooRexx
ApplicationWriter
AuthorsNicole Scholz
Supported Versions2.0.x  
Supported OS
QuestionHow can I adjust table cell text?
Answer

In this example table cell text is adjusted to the right.

Code-Snippet-Listing (snippet-source)

/* adjust table cell text to the right */

/* Retrieve the Desktop object, we need its XComponentLoader interface to load a new document*/
oDesktop         = UNO.createDesktop()    -- get the UNO Desktop service object
xComponentLoader = oDesktop~XDesktop~XComponentLoader  -- get componentLoader interface
/* open the blank file */
url = "private:factory/swriter"
xWriterComponent = xComponentLoader~loadComponentFromURL(url, "_blank", 0, .UNO~noProps)

  -- import the enum
call bsf.import "com.sun.star.style.ParagraphAdjust", "paragraphAdjust"

xDocumentFactory = xWriterComponent~XMultiServiceFactory
xTextDocument = xWriterComponent~XTextDocument
xText = xTextDocument~getText()
xTextCursor = xText~createTextCursor()
xPropertySet = xTextCursor~xPropertySet
xDMsf = xTextDocument~XMultiServiceFactory

/* create the table */
xTextTable = xDMsf~createInstance("com.sun.star.text.TextTable")~XTextTable
xTextTable~initialize(1, 2) -- initialize the table

/* insert TextTable in the Text */
xText~insertTextContent(xTextCursor, xTextTable, .false)

/* insert text into the table */
call setCellText "A1", "text", xTextTable

::requires UNO.cls

  -- routine to set the cell text
::routine setCellText
  use arg cell, text, xTextTable
	xCellText = xTextTable~getCellByName(cell)~XText
	xCellCursor = xCellText~createTextCursor()
		-- set the property of the cell text
	cursorProps = xCellCursor~XPropertySet
  -- adjust the cell text to the right
	cursorProps~setPropertyValue("ParaAdjust", .paragraphAdjust~"RIGHT")
	xCellText~setString(text)
	return

Changelog

DateUserModification

and