Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ public class Row implements Iterable<Cell> {
private final int rowNum;
private final List<Cell> cells;
private final int physicalCellCount;
private final boolean isHidden;

Row(int rowNum, int physicalCellCount, List<Cell> cells) {
Row(int rowNum, int physicalCellCount, List<Cell> cells, boolean isHidden) {
this.rowNum = rowNum;
this.physicalCellCount = physicalCellCount;
this.cells = cells;
this.isHidden = isHidden;
}

/**
Expand Down Expand Up @@ -81,6 +83,15 @@ public int getPhysicalCellCount() {
return physicalCellCount;
}

/**
* Indicates whether this row is hidden in the worksheet.
*
* @return {@code true} if the row is hidden; {@code false} otherwise
*/
public boolean isHidden() {
return isHidden;
}

@Override
public String toString() {
return "Row " + rowNum + ' ' + cells;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private Row next() throws XMLStreamException {

int trackedColIndex = 0;
int rowIndex = getRowIndexWithFallback(++trackedRowIndex);
boolean isHidden = "1".equals(r.getAttribute("hidden"));

List<Cell> cells = new ArrayList<>(rowCapacity);
int physicalCellCount = 0;
Expand All @@ -103,7 +104,7 @@ private Row next() throws XMLStreamException {
physicalCellCount++;
}
rowCapacity = Math.max(rowCapacity, cells.size());
return new Row(rowIndex, physicalCellCount, cells);
return new Row(rowIndex, physicalCellCount, cells, isHidden);
}

private int getRowIndexWithFallback(int fallbackRowIndex) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package org.dhatim.fastexcel.reader;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;

import static org.assertj.core.api.Assertions.assertThat;
import static org.dhatim.fastexcel.reader.Resources.open;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand All @@ -25,4 +29,49 @@ public void testGetCellByAddress() throws IOException {
assertEquals(cellIndex0, cellA1);
}
}

@ParameterizedTest
@CsvSource({
"0, false, 1, Lorem, 43101, 1+A1, true",
"1, true, 2, ipsum, 43102, 1+A2, false",
"2, true, 3, dolor, 43103, 1+A3, true",
"3, false, 4, sit, 43104, 1+A4, false",
"4, false, 5, amet, 43105, 1+A5, true",
"5, false, 6, consectetur, 43106, 1+A6, false",
"6, true, 7, adipiscing, 43107, 1+A7, true",
"7, true, 8, elit, 43108, 1+A8, false",
"8, true, 9, Ut, 43109, 1+A9, true",
"9, false, 10, nec, 43110, 1+A10, false"
})
public void shouldGetVisibleAndHiddenRows(int index, boolean isHidden, String cellIndex0, String cellIndex1, int cellIndex2, String cellIndex3,
boolean cellIndex4) throws IOException {
try (InputStream inputStream = open("/xlsx/simple-with-hidden-rows.xlsx");
ReadableWorkbook excel = new ReadableWorkbook(inputStream)) {
Sheet firstSheet = excel.getFirstSheet();

Row row = firstSheet.read().get(index);

assertThat(row.isHidden()).isEqualTo(isHidden);
assertThat(row.getCell(0)).satisfies(cell -> {
assertThat(cell.getType()).isEqualTo(CellType.NUMBER);
assertThat(cell.asNumber()).isEqualTo(new BigDecimal(cellIndex0));
});
assertThat(row.getCell(1)).satisfies(cell -> {
assertThat(cell.getType()).isEqualTo(CellType.STRING);
assertThat(cell.asString()).isEqualTo(cellIndex1);
});
assertThat(row.getCell(2)).satisfies(cell -> {
assertThat(cell.getType()).isEqualTo(CellType.NUMBER);
assertThat(cell.asNumber()).isEqualTo(new BigDecimal(cellIndex2));
});
assertThat(row.getCell(3)).satisfies(cell -> {
assertThat(cell.getType()).isEqualTo(CellType.FORMULA);
assertThat(cell.getFormula()).isEqualTo(cellIndex3);
});
assertThat(row.getCell(4)).satisfies(cell -> {
assertThat(cell.getType()).isEqualTo(CellType.BOOLEAN);
assertThat(cell.asBoolean()).isEqualTo(cellIndex4);
});
}
}
}
Binary file not shown.