diff --git a/src/main/java/org/awdevelopment/smithlab/io/input/XlsxHeaderReader.java b/src/main/java/org/awdevelopment/smithlab/io/input/XlsxHeaderReader.java index 8a7e1fd..d171a19 100644 --- a/src/main/java/org/awdevelopment/smithlab/io/input/XlsxHeaderReader.java +++ b/src/main/java/org/awdevelopment/smithlab/io/input/XlsxHeaderReader.java @@ -16,6 +16,10 @@ public static Headers readHeaders(LoggerHelper LOGGER, XSSFSheet sheet) throws I int rowZeroWidth = sheet.getRow(0).getLastCellNum(); for (int i = 0; i < rowZeroWidth; i++) { XSSFCell cell = sheet.getRow(0).getCell(i); + if (cell == null) { + LOGGER.atWarn("Cell in header row at zero-indexed column "+i+" is null, skipping..."); + continue; + } CellType cellType = cell.getCellType(); if (cellType == CellType._NONE || cellType == CellType.BLANK || cellType == CellType.ERROR) { LOGGER.atWarn("Cell in header row at zero-indexed column "+i diff --git a/src/main/java/org/awdevelopment/smithlab/io/input/XlsxInputReader.java b/src/main/java/org/awdevelopment/smithlab/io/input/XlsxInputReader.java index b1800a6..43878ec 100644 --- a/src/main/java/org/awdevelopment/smithlab/io/input/XlsxInputReader.java +++ b/src/main/java/org/awdevelopment/smithlab/io/input/XlsxInputReader.java @@ -253,7 +253,27 @@ private Condition readCondition(XSSFCell cell) throws InvalidConditionValueExcep } } + private boolean isCellInMergedRegion(XSSFCell cell) { + XSSFSheet sheet = cell.getSheet(); + int rowIndex = cell.getRowIndex(); + int colIndex = cell.getColumnIndex(); + return sheet.getMergedRegions().stream().anyMatch(region -> region.isInRange(rowIndex, colIndex)); + } + private Strain readStrain(XSSFCell cell, Condition condition) throws InvalidStrainValueException { + int rowIndex = cell.getRowIndex(); + int colIndex = cell.getColumnIndex(); + // Check if the cell is in a merged region + if (cell == null || isCellInMergedRegion(cell)) { + while (cell == null || cell.getCellType() == CellType.BLANK || cell.getCellType() == CellType.ERROR) { + if (rowIndex == 0) break; + rowIndex--; + cell = cell.getSheet().getRow(rowIndex).getCell(colIndex); + rowIndex = cell.getRowIndex(); + colIndex = cell.getColumnIndex(); + } + } + CellType cellType = cell.getCellType(); if (cellType == CellType.STRING) { String cellContent = cell.getStringCellValue(); @@ -265,8 +285,6 @@ private Strain readStrain(XSSFCell cell, Condition condition) throws InvalidStra strains.add(newStrain); return newStrain; } else if (cellType == CellType.BLANK || cellType == CellType._NONE) { - int rowIndex = cell.getRowIndex(); - int colIndex = cell.getColumnIndex(); for (int i = rowIndex - 1; i > 1; i--) { XSSFCell nextCell = cell.getSheet().getRow(i).getCell(colIndex); if (nextCell.getCellType() == CellType.STRING) return readStrain(nextCell, condition);