Skip to content

Commit

Permalink
Fix #285: Skip repeated rows and columns when possible
Browse files Browse the repository at this point in the history
According to the ODF 1.3 spec, repeated columns cannot contain cells
which span multiple rows or columns and repeated rows cannot contain
vertical merges. Therefore, we can skip repeated rows and columns after
the first one while searching for covering cells.

Note that while this code should properly handle horizontal merges in
repeated rows, such merges are ignored after the first instance of the
repeated row in current versions of LibreOffice, OpenOffice, and Excel,
so this scenario is unlikely to come up.
  • Loading branch information
Nnnes authored and mistmist committed Apr 19, 2024
1 parent c6b9224 commit 27d45bc
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions odfdom/src/main/java/org/odftoolkit/odfdom/doc/table/OdfTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -2276,16 +2276,27 @@ boolean isCoveredCellInOwnerTable(List<CellCoverInfo> coverList, int nCol, int n
List<CellCoverInfo> getCellCoverInfos(int nStartCol, int nStartRow, int nEndCol, int nEndRow) {
List<CellCoverInfo> coverList = new ArrayList<CellCoverInfo>();
int nColSpan, nRowSpan;
for (int i = nStartCol; i < nEndCol + 1; i++) {
for (int j = nStartRow; j < nEndRow + 1; j++) {
OdfTableCell cell = getCellByPosition(i, j);
if (cell != null) {
nColSpan = cell.getColumnSpannedNumber();
nRowSpan = cell.getRowSpannedNumber();
if ((nColSpan > 1) || (nRowSpan > 1)) {
coverList.add(new CellCoverInfo(i, j, nColSpan, nRowSpan));
for (int i = nStartRow; i < nEndRow + 1; ) {
OdfTableRow row = getRowByIndex(i);
if (row != null) {
for (int j = nStartCol; j < nEndCol + 1; ) {
OdfTableCell cell = getCellByPosition(j, i);
if (cell != null) {
nColSpan = cell.getColumnSpannedNumber();
nRowSpan = cell.getRowSpannedNumber();
if ((nColSpan > 1) || (nRowSpan > 1)) {
for (int k = 0; k < row.getRowsRepeatedNumber(); k++) {
coverList.add(new CellCoverInfo(j, i + k, nColSpan, nRowSpan));
}
}
j += cell.getColumnsRepeatedNumber();
} else {
j++;
}
}
i += row.getRowsRepeatedNumber();
} else {
i++;
}
}
return coverList;
Expand Down

0 comments on commit 27d45bc

Please sign in to comment.