Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Jan 19, 2024
1 parent 1080fb7 commit cd15a01
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,13 @@ public Comment getCellComment(CellAddress cellAddress) {
/**
* Only works after sheet is fully read (because merged regions data is stored
* at the end of the sheet XML).
*
* @param index the index of the merged region to retrieve
* @return the merged region at the specified index
* @throws NoSuchElementException if the index argument is not a valid index
*/
@Override
public CellRangeAddress getMergedRegion(int index) {
public CellRangeAddress getMergedRegion(int index) throws NoSuchElementException {
List<CellRangeAddress> regions = getMergedRegions();
if(index > regions.size()) {
throw new NoSuchElementException("index " + index + " is out of range");
Expand Down Expand Up @@ -217,7 +221,7 @@ public Hyperlink getHyperlink(int row, int column) {
* This should only be called after all the rows are read because the hyperlink data is
* at the end of the sheet.
*
* @param cellAddress
* @param cellAddress the location of the cell
* @return the hyperlink associated with this cell (only if feature is enabled on the Builder) - null if not found
* @throws IllegalStateException if {@link com.github.pjfanning.xlsx.StreamingReader.Builder#setReadHyperlinks(boolean)} is not set to true
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ public String getSheetName(int sheet) {
}

/**
* {@inheritDoc}
* Returns the index of the sheet by his name (case insensitive match)
*
* @param name the sheet name
* @return index of the sheet (0 based) or {@code -1} if not found
*/
@Override
public int getSheetIndex(String name) {
Expand All @@ -81,7 +84,7 @@ public int getSheetIndex(String name) {
* Returns the index of the given sheet
*
* @param sheet the sheet to look up
* @return index of the sheet (0 based)
* @return index of the sheet (0 based) or {@code -1} if not found
* @throws IllegalArgumentException if the sheet provided is not a StreamingSheet
*/
@Override
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/com/github/pjfanning/xlsx/StreamingSheetTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ public void testMissingSheet() throws Exception {
}
}

@Test
public void testSheetIndexForMissingSheet() throws Exception {
try(
InputStream is = getInputStream("empty_sheet.xlsx");
Workbook workbook = StreamingReader.builder().open(is)
) {
assertEquals(-1, workbook.getSheetIndex("non-existent"));
}
}

@Test
public void testEmptyCellShouldHaveGeneralStyle() throws Exception {
try(
Expand Down

0 comments on commit cd15a01

Please sign in to comment.