// then this repeated column have to split to repeated number columns
// the maColumnElement should also be updated according to the original
// index in the repeated column
void splitRepeatedColumns() {
Table table = getTable();
TableTableElement tableEle = table.getOdfElement();
int repeateNum = getColumnsRepeatedNumber();
if (repeateNum > 1) {
// change this repeated column to several single columns
TableTableColumnElement ownerColumnElement = null;
String columnWidthStr = null;
long columnWidth = 0;
int repeatedColumnIndex = mnRepeatedIndex;
Node refElement = maColumnElement;
maColumnElement.removeAttributeNS(OdfDocumentNamespace.TABLE.getUri(), "number-columns-repeated");
String originalWidth = maColumnElement.getProperty(OdfTableColumnProperties.ColumnWidth);
String originalRelWidth = maColumnElement.getProperty(OdfTableColumnProperties.RelColumnWidth);
if (originalWidth != null) {
columnWidthStr = Length.mapToUnit(originalWidth, Unit.MILLIMETER);
columnWidth = PositiveLength.parseLong(columnWidthStr, Unit.MILLIMETER);
}
for (int i = repeateNum - 1; i >= 0; i--) {
TableTableColumnElement newColumn = (TableTableColumnElement) OdfXMLFactory.newOdfElement(
(OdfFileDom) maColumnElement.getOwnerDocument(), OdfName.newName(OdfDocumentNamespace.TABLE,
"table-column"));
if (originalWidth != null && originalWidth.length() > 0) {
newColumn.setProperty(OdfTableColumnProperties.ColumnWidth, originalWidth);
}
if (originalRelWidth != null && originalRelWidth.length() > 0) {
long relWidth = (long) ((DEFAULT_REL_TABLE_WIDTH / table.getWidth()) * columnWidth);
newColumn.setProperty(OdfTableColumnProperties.RelColumnWidth, String.valueOf(relWidth) + "*");
}
tableEle.insertBefore(newColumn, refElement);
refElement = newColumn;
if (repeatedColumnIndex == i) {
ownerColumnElement = newColumn;
} else {
table.updateColumnRepository(maColumnElement, i, newColumn, 0);
}
}
// remove this column element
tableEle.removeChild(maColumnElement);
if (ownerColumnElement != null) {
table.updateColumnRepository(maColumnElement, mnRepeatedIndex, ownerColumnElement, 0);
// update column element.
maColumnElement = ownerColumnElement;