0

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.

John Manko
  • 1,828
  • 27
  • 51
  • See: http://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1text_1_1XTextTable.html#a2cd2e4d8366b38edb09a0861c0f7f880 there getCellByName([in] string aCellName) – Axel Richter Aug 23 '14 at 05:01
  • That's the problem; I don't have the cell name. I have the cell and the TextTable, though. – John Manko Aug 23 '14 at 19:30

2 Answers2

1

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
        }

}
John Manko
  • 1,828
  • 27
  • 51
0

If you have a com.sun.star.text.Cell, then this class includes the service com.sun.star.text.CellProperties. This service provides a attribute CellName.

http://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1text_1_1Cell.html

So, if your xCell really is a com.sun.star.text.Cell, then

textTableCursor = xTextTable.createCursorByCellName(xCell.getPropertyValue("CellName"));

But there is no method getCell in libreoffice API, so I don't know what this really will return.

Greetings

Axel

Axel Richter
  • 56,077
  • 6
  • 60
  • 87