OO-Snippets: change table column width

Commons

Keywordswidth, column width, change table column width
LanguageooRexx
ApplicationWriter
AuthorsNicole Scholz
Supported Versions
Supported OS
QuestionHow can I change the width of a table column
Answer

In this example the column width of a table is changed.

Code-Snippet-Listing (snippet-source)

/* change the table width */

/* 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 */
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", "table width", xTextTable
call setColumnWidth "A1", 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()
	cursorProps = xCellCursor~XPropertySet
	xCellText~setString(text)
	return

  -- routine to change the column width of a table
::routine setColumnWidth
    use arg cell, xTextTable
  xTextTableCursor = xTextTable~createCursorByCellName(cell)
  xTableProps=xTextTable~xPropertySet
  colRelSum=xTableProps~getPropertyValue("TableColumnRelativeSum") -- usually: 10000
  colSeparators=xTableProps~getPropertyValue("TableColumnSeparators") -- total sum
  colSeparators[1]~position=trunc(colRelSum*0.70)  -- new position of the column separator
  -- set the property with the calculated position of the seperator
  xTableProps~setPropertyValue("TableColumnSeparators", colSeparators)
  return

Changelog

DateUserModification

and