<?xml version="1.0"?> | |
<!-- | |
$RCSfile: Writer.MergeTableCells.snip,v $ | |
last change: $Revision: 1.1 $ $Author: tomsontom $ $Date: 2008/10/20 11:29:28 $ | |
(c)2008 by the copyright holders listed with the author-tags. | |
If no explicit copyright holder is mentioned with a certain author, | |
the author him-/herself is the copyright holder. All rights reserved. | |
Public Documentation License Notice: | |
The contents of this Documentation are subject to the | |
Public Documentation License Version 1.0 (the "License"); | |
you may only use this Documentation if you comply with | |
the terms of this License. A copy of the License is | |
available at http://www.openoffice.org/licenses/PDL.html | |
The Original Documentation can be found in the CVS archives | |
of openoffice.org at the place specified by RCSfile: in this header. | |
The Initial Writer(s) of the Original Documentation are listed | |
with the author-tags below. | |
The Contributor(s) are listed with the author-tags below | |
without the marker for being an initial author. | |
All Rights Reserved. | |
--> | |
<snippet language="ooRexx" application="Writer"> | |
<keywords> | |
<keyword>merge</keyword> | |
<keyword>table cell</keyword> | |
<keyword>merge table cells</keyword> | |
</keywords> | |
<authors> | |
<author id="" initial="false" email="">Nicole Scholz</author> | |
</authors> | |
<question heading="merge table cells">How can I merge table cells? | |
</question> | |
<answer> | |
<p>In this example a table with three columns is created.</p> | |
<p>The first two cells are merged to one cell.</p> | |
<listing>/* 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~{%see com.sun.star.frame.XDesktop%XDesktop}~{%see com.sun.star.frame.XComponentLoader%XComponentLoader} -- get componentLoader interface | |
/* open the blank file */ | |
url = "private:factory/swriter" | |
xWriterComponent = xComponentLoader~loadComponentFromURL(url, "_blank", 0, .UNO~noProps) | |
xDocumentFactory = xWriterComponent~{%see com.sun.star.lang.XMultiServiceFactory%XMultiServiceFactory} | |
xTextDocument = xWriterComponent~{%see com.sun.star.text.XTextDocument%XTextDocument} | |
xText = xTextDocument~getText() | |
xTextCursor = xText~createTextCursor() | |
xPropertySet = xTextCursor~{%see com.sun.star.beans.XPropertySet%xPropertySet} | |
xDMsf = xTextDocument~{%see com.sun.star.lang.XMultiServiceFactory%XMultiServiceFactory} | |
/* create the table with 3 columns*/ | |
xTextTable = xDMsf~createInstance("{%see com.sun.star.text.TextTable}")~{%see com.sun.star.text.XTextTable%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)~{%see com.sun.star.text.XText%XText} | |
xCellCursor = xCellText~createTextCursor() | |
cursorProps = xCellCursor~{%see com.sun.star.beans.XPropertySet%XPropertySet} | |
xCellText~setString(text) | |
return | |
</listing> | |
</answer> | |
<versions> | |
<version number="2.0.x" status="tested"/> | |
</versions> | |
<operating-systems> | |
</operating-systems> | |
<changelog> | |
</changelog> | |
</snippet> |