我需要在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
列和行索引查找它,以获取XTextTableCursor
个对象通过xTextTable.createCursorByCellName
。
答案 0 :(得分: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
}
}
答案 1 :(得分: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方法,所以我不知道这会带来什么。
问候
阿克塞尔