OO-Snippets: merge table cells

Commons

Keywordsmerge, table cell, merge table cells
LanguageooRexx
ApplicationWriter
AuthorsNicole Scholz
Supported Versions2.0.x  
Supported OS
QuestionHow can I merge table cells?
Answer

In this example a table with three columns is created.

The first two cells are merged to one cell.

Code-Snippet-Listing (snippet-source)

/* merge table columns */

/* 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)

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

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

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

/* insert text into the table */
call setCellText "A1", "merge colum A1 and B1", xTextTable

  -- merge colum A1 and B1
xTextTableCursor=xTextTable~createCursorByCellName("A1") -- create cursor
xTextTableCursor~gotoCellByName("B1", .true)             -- select area up to and including this cell
xTextTableCursor~mergeRange                                -- merge selected cells
xTextTable~createCursorByCellName("A1") ~~gotoCellByName("B1", .true)

::requires UNO.cls

  -- routine to set the cell text
::routine setCellText
  	use arg cell, text, xTextTable
	xCellText = xTextTable~getCellByName(cell)~XText
	xCellCursor = xCellText~createTextCursor()
	cursorProps = xCellCursor~XPropertySet
	xCellText~setString(text)
	return

Changelog

DateUserModification

and