首页 文章

LibreOffice UNO Writer获取单元名称

提问于
浏览
0

我需要在Writer表中合并单元格,但是我在找到我所拥有的单元格的名称时遇到了问题 .

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) {
 }

我需要找出如何获取 XCell 的名称,或者如何根据 short 列和行索引找到它,以便通过 xTextTable.createCursorByCellName 获取 XTextTableCursor 对象 .

2 回答

  • 1

    阿克塞尔,

    那种指向正确的方向,但我应该注意到XCell接口没有getPropertyValue方法 . 相反,需要获取XCell对象的XPropertySet . 以下是完整的代码:

    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
            }
    
    }
    
  • 0

    如果您有 com.sun.star.text.Cell ,则此类包含服务 com.sun.star.text.CellProperties . 此服务提供属性CellName .

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

    那么,如果你的xCell真的是com.sun.star.text.Cell,那么

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

    但是在libreoffice API中没有getCell方法,所以我不知道这究竟会返回什么 .

    问候

    阿克塞尔

相关问题