//rather than merge to a big cell.
if (rowCount == (mnEndRow - mnStartRow + 1)
&& colCount == (mnEndColumn - mnStartColumn + 1)
&& !mbSpreadsheet) {
if (firstCell.getOdfElement() instanceof TableTableCellElement) {
TableTableCellElement firstCellElement = (TableTableCellElement) (firstCell.getOdfElement());
firstCellElement.removeAttributeNS(OdfDocumentNamespace.TABLE.getUri(), "number-columns-spanned");
firstCellElement.removeAttributeNS(OdfDocumentNamespace.TABLE.getUri(), "number-rows-spanned");
firstCellElement.setOfficeValueTypeAttribute(OfficeValueTypeAttribute.Value.STRING.toString());
}
//just copy the text of the other cells to this first cell
for (int i = mnStartRow; i < mnEndRow + 1; i++) {
for (int j = mnStartColumn; j < mnEndColumn + 1; j++) {
OdfTableCell cellBase = maOwnerTable.getCellByPosition(j, i);
if (j != mnStartColumn || i != mnStartRow) {
//copy the content of this cell to the first cell
firstCell.appendContentFrom(cellBase);
}
}
}
maOwnerTable.removeRowsByIndex(1, maOwnerTable.getRowCount() - 1);
maOwnerTable.removeColumnsByIndex(1, maOwnerTable.getColumnCount() - 1);
OdfTableColumn firstColumn = maOwnerTable.getColumnByIndex(0);
firstColumn.setWidth(maOwnerTable.getWidth());
mnEndRow = mnStartRow;
mnEndColumn = mnStartColumn;
return;
} //if the cell range covered all the table row, and the merged column > 1
//the merged column can be removed
else if (rowCount == (mnEndRow - mnStartRow + 1)
&& colCount > (mnEndColumn - mnStartColumn + 1)
&& (mnEndColumn - mnStartColumn) > 0) {
//the first cell, set the span attribute
if (firstCell.getOdfElement() instanceof TableTableCellElement) {
TableTableCellElement firstCellElement = (TableTableCellElement) (firstCell.getOdfElement());
firstCellElement.removeAttributeNS(OdfDocumentNamespace.TABLE.getUri(), "number-columns-spanned");
firstCellElement.setTableNumberRowsSpannedAttribute(Integer.valueOf(mnEndRow - mnStartRow + 1));
firstCellElement.setOfficeValueTypeAttribute(OfficeValueTypeAttribute.Value.STRING.toString());
}
//the other cell, copy the content to first cell
//if it is also in the first column of the cell range, set to the covered cell
//other cell not in the first column will be removed when remove the column
for (int i = mnStartRow; i < mnEndRow + 1; i++) {
for (int j = mnStartColumn; j < mnEndColumn + 1; j++) {
OdfTableCell cellBase = maOwnerTable.getCellByPosition(j, i);
if (j != mnStartColumn || i != mnStartRow) {
//append content to first cell
firstCell.appendContentFrom(cellBase);
//change the cell in the first column of cell range to covered cell
if ((j == mnStartColumn) && (cellBase.getOdfElement() instanceof TableTableCellElement)) {
//change the normal cell to be the covered cell
TableTableCellElement firstColumnCell = (TableTableCellElement) cellBase.getOdfElement();
TableCoveredTableCellElement coveredCell = (TableCoveredTableCellElement) OdfXMLFactory.newOdfElement(
(OdfFileDom) firstColumnCell.getOwnerDocument(),
OdfName.newName(OdfDocumentNamespace.TABLE, "covered-table-cell"));
OdfTableRow parentRow = cellBase.getTableRow();
parentRow.getOdfElement().insertBefore(coveredCell, firstColumnCell);
parentRow.getOdfElement().removeChild(firstColumnCell);
}
}
}
}
List<Long> widthList = getCellRangeWidthList();
long nCellRangeWidth = widthList.get(widthList.size() - 1).longValue() - widthList.get(0).longValue();
maOwnerTable.removeColumnsByIndex(mnStartColumn + 1, mnEndColumn - mnStartColumn);
OdfTableColumn firstColumn = maOwnerTable.getColumnByIndex(mnStartColumn);
firstColumn.setWidth(nCellRangeWidth);
mnEndColumn = mnStartColumn;
return;
} //if the cell range covered all the table column, the merged row can be removed
else if (rowCount > (mnEndRow - mnStartRow + 1)
&& colCount == (mnEndColumn - mnStartColumn + 1)
&& (mnEndRow - mnStartRow) > 0) {
//the first cell, set the span attribute
if (firstCell.getOdfElement() instanceof TableTableCellElement) {
TableTableCellElement firstCellElement = (TableTableCellElement) (firstCell.getOdfElement());
firstCellElement.removeAttributeNS(OdfDocumentNamespace.TABLE.getUri(), "number-rows-spanned");
firstCellElement.setTableNumberColumnsSpannedAttribute(Integer.valueOf(mnEndColumn - mnStartColumn + 1));
firstCellElement.setOfficeValueTypeAttribute(OfficeValueTypeAttribute.Value.STRING.toString());
}
//the other cell, copy the content to first cell
//if it is also in the first row of the cell range, set to the covered cell
//other cell not in the first row will be removed when remove the row
for (int i = mnStartRow; i < mnEndRow + 1; i++) {
for (int j = mnStartColumn; j < mnEndColumn + 1; j++) {
OdfTableCell cellBase = maOwnerTable.getCellByPosition(j, i);
if (j != mnStartColumn || i != mnStartRow) {
//append content to first cell
firstCell.appendContentFrom(cellBase);
//change the cell in the first row of cell range to covered cell
if ((i == mnStartRow) && (cellBase.getOdfElement() instanceof TableTableCellElement)) {
//change the normal cell to be the covered cell
TableTableCellElement firstRowCell = (TableTableCellElement) cellBase.getOdfElement();
TableCoveredTableCellElement coveredCell = (TableCoveredTableCellElement) OdfXMLFactory.newOdfElement(
(OdfFileDom) firstRowCell.getOwnerDocument(),
OdfName.newName(OdfDocumentNamespace.TABLE, "covered-table-cell"));
OdfTableRow parentRow = cellBase.getTableRow();
parentRow.getOdfElement().insertBefore(coveredCell, firstRowCell);
parentRow.getOdfElement().removeChild(firstRowCell);
}
}
}
}
maOwnerTable.removeRowsByIndex(mnStartRow + 1, mnEndRow - mnStartRow);
mnEndRow = mnStartRow;
return;
} //don't remove any row/column
else {
//first keep the column and row count in this cell range
//the first cell, set the span attribute
if (firstCell.getOdfElement() instanceof TableTableCellElement) {
TableTableCellElement firstCellElement = (TableTableCellElement) (firstCell.getOdfElement());
firstCellElement.setTableNumberColumnsSpannedAttribute(Integer.valueOf(mnEndColumn - mnStartColumn + 1));
firstCellElement.setTableNumberRowsSpannedAttribute(Integer.valueOf(mnEndRow - mnStartRow + 1));
firstCellElement.setOfficeValueTypeAttribute(OfficeValueTypeAttribute.Value.STRING.toString());
}
//the other cell, set to the covered cell
for (int i = mnStartRow; i < mnEndRow + 1; i++) {
for (int j = mnStartColumn; j < mnEndColumn + 1; j++) {
OdfTableCell cellBase = maOwnerTable.getCellByPosition(j, i);
if (j != mnStartColumn || i != mnStartRow) {
if (cellBase.getOdfElement() instanceof TableTableCellElement) {
//change the normal cell to be the covered cell
TableTableCellElement cell = (TableTableCellElement) cellBase.getOdfElement();
TableCoveredTableCellElement coveredCell = (TableCoveredTableCellElement) OdfXMLFactory.newOdfElement(
(OdfFileDom) cell.getOwnerDocument(),
OdfName.newName(OdfDocumentNamespace.TABLE, "covered-table-cell"));
OdfTableRow parentRow = cellBase.getTableRow();
parentRow.getOdfElement().insertBefore(coveredCell, cell);
//copy the content of this cell to the first cell
firstCell.appendContentFrom(cellBase);
cellBase.removeContent();
//set the table column repeated attribute
int repeatedNum = cell.getTableNumberColumnsRepeatedAttribute().intValue();
int num = (mnEndColumn - j + 1) - repeatedNum;
if (num >= 0) {
coveredCell.setTableNumberColumnsRepeatedAttribute(Integer.valueOf(repeatedNum));
parentRow.getOdfElement().removeChild(cell);
} else {
coveredCell.setTableNumberColumnsRepeatedAttribute(new Integer(mnEndColumn - j + 1));
cell.setTableNumberColumnsRepeatedAttribute(Integer.valueOf(-num));
}
} else if (cellBase.getOdfElement() instanceof TableCoveredTableCellElement) {
try {
//copy the content of this cell to the first cell