I need to merge cells in a Writer table, but I'm having problems finding the name of the cell I have.
XCell xCell = getCell(column, row);
XTextTableCursor textTableCursor = null;
try {
textTableCursor = xTextTable.createCursorByCellName(???????????);
textTableCursor.goRight(mergeCol, true);
textTableCursor.goDown(mergeRow, true);
textTableCursor.mergeRange();
} catch (Exception ex) {
}
I need to find out how to get the name of the XCell
, or how to find it based on a short
column and row index, in order to get a XTextTableCursor
object via xTextTable.createCursorByCellName
.
Axel,
That sort of pointed me in the right direction, but I should note that the XCell interface doesn't have a getPropertyValue method. Instead, one needs to get the XPropertySet of the XCell object. Here is the full code that does work:
public void mergeCells(int startColumn, int startRow, short endColumn, short endRow) {
if (endRow == 0 && endColumn == 0) {
return;
}
XCell xCell = getCell(column, row); //Custom method to get cell
XPropertySet props = null;
try {
props = (XPropertySet) FileManager.getOOoUnoRuntimeQueryInterface(XPropertySet.class, xCell);
} catch (Exception ex) {
// Do error stuff
}
XTextTableCursor textTableCursor = null;
String cellName = null;
try {
cellName = props.getPropertyValue("CellName").toString();
} catch (Exception ex) {
// Do error stuff
}
try {
textTableCursor = xTextTable.createCursorByCellName(cellName);
textTableCursor.goRight(endColumn, true);
textTableCursor.goDown(endRow, true);
textTableCursor.mergeRange();
} catch (Exception ex) {
// Do error stuff
}
}