From 858f0bbc2cce47fe8bc1c0337d7a46077ce93e0e Mon Sep 17 00:00:00 2001 From: Miguel Chacon Date: Fri, 22 Dec 2023 03:45:05 +0000 Subject: [PATCH] Fix issue #86 related to duplicate lines --- resources/features/bugs/cellContent.feature | 21 +++++++++++++++++ src/com/github/miachm/sods/OdsReader.java | 26 ++++++++++++--------- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/resources/features/bugs/cellContent.feature b/resources/features/bugs/cellContent.feature index aa1d1e9..8d679fe 100644 --- a/resources/features/bugs/cellContent.feature +++ b/resources/features/bugs/cellContent.feature @@ -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 | + diff --git a/src/com/github/miachm/sods/OdsReader.java b/src/com/github/miachm/sods/OdsReader.java index ddaa522..1eaeb24 100644 --- a/src/com/github/miachm/sods/OdsReader.java +++ b/src/com/github/miachm/sods/OdsReader.java @@ -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); } } } @@ -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 @@ -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 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 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); @@ -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)