【问题标题】:LibreOffice UNO Writer get cell nameLibreOffice UNO Writer 获取单元格名称
【发布时间】:2014-10-16 21:34:31
【问题描述】:

我需要合并 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 对象。

【问题讨论】:

  • 参见:api.libreoffice.org/docs/idl/ref/… 那里 getCellByName([in] string aCellName)
  • 这就是问题所在;我没有单元格名称。不过,我有单元格和 TextTable。

标签: java libreoffice openoffice-writer uno


【解决方案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
        }

}

【讨论】:

    【解决方案2】:

    如果您有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 方法,所以我不知道这到底会返回什么。

    问候

    阿克塞尔

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-04
      • 2013-07-12
      相关资源
      最近更新 更多