Skip to content

Commit

Permalink
Fix issue #86 related to duplicate lines
Browse files Browse the repository at this point in the history
  • Loading branch information
miachm committed Dec 22, 2023
1 parent 3a45a31 commit 858f0bb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
21 changes: 21 additions & 0 deletions resources/features/bugs/cellContent.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,24 @@ Feature: Bugs related to invalid cell value content in SODS
Then the cell values are:
| Test 1 |
| A |

Scenario: Repeated rows were ignoring cell data
When load a spreadsheet from the resource "repeatedRows"
When get the first sheet
Then the cell values are:
| header1 | header2 | header3 |
| 1 | 2 | 3 |
| 2 | 3 | 1 |
| 1 | 2 | 2 |
| 1 | 2 | 3 |
| 1 | 2 | 3 |
| 5 | 5 | 5 |
| 3 | 3 | 3 |
| 3 | 3 | 3 |
| 3 | 3 | 3 |
| 3 | 3 | 3 |
| 3 | 3 | 3 |
| 3 | 3 | 3 |
| 2 | 2 | 2 |
| 1 | 1 | 1 |

26 changes: 15 additions & 11 deletions src/com/github/miachm/sods/OdsReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ else if (instance.getTag().equals("table:table-row")) {
if (rowStyle != null)
sheet.setRowHeights(sheet.getMaxRows()-numRows, numRows, rowStyle.getHeight());
}
processCells(instance, sheet);
processCells(instance, sheet, numRows);
}
}
}
Expand Down Expand Up @@ -404,7 +404,7 @@ private void parseColumnProperties(XmlReaderInstance instance, Sheet sheet, Styl
}
}

private void processCells(XmlReaderInstance reader, Sheet sheet) {
private void processCells(XmlReaderInstance reader, Sheet sheet, int number_rows_repeated) {
int column = 0;
while (reader.hasNext()) {
// number of columns repeated
Expand Down Expand Up @@ -435,15 +435,19 @@ private void processCells(XmlReaderInstance reader, Sheet sheet) {
if (columnsSpanned != null) {
columns = Integer.parseInt(columnsSpanned);
}

int positionX = sheet.getMaxRows()-1;
int positionY = column;
if (rows != 1 || columns != 1) {
Pair<Vector, Vector> pair = new Pair<>();
pair.first = new Vector(positionX, positionY);
pair.second = new Vector(rows, columns);
groupCells.add(pair);

if (number_rows_repeated == 1) {
int positionX = sheet.getMaxRows()-1;
int positionY = column;
if (rows != 1 || columns != 1) {
Pair<Vector, Vector> pair = new Pair<>();
pair.first = new Vector(positionX, positionY);
pair.second = new Vector(rows, columns);
groupCells.add(pair);
}
}
int positionX = sheet.getMaxRows()-number_rows_repeated;
int positionY = column;

OfficeValueType valueType = OfficeValueType.ofReader(instance);
Object value = valueType.read(instance);
Expand All @@ -459,7 +463,7 @@ private void processCells(XmlReaderInstance reader, Sheet sheet) {
sheet.appendColumns(positionY + number_columns_repeated - sheet.getMaxColumns());
}

Range range = sheet.getRange(positionX, positionY, 1, number_columns_repeated);
Range range = sheet.getRange(positionX, positionY, number_rows_repeated, number_columns_repeated);

String formula = instance.getAttribValue("table:formula");
if (formula != null)
Expand Down

0 comments on commit 858f0bb

Please sign in to comment.