#I5OSFC 修复,错误异常信息修改

This commit is contained in:
Husky 2022-08-30 14:43:39 +08:00
parent f7ebc9f0fa
commit a09dd3966b
3 changed files with 20 additions and 1 deletions

View File

@ -44,7 +44,9 @@ public class MapSheetReader extends AbstractSheetReader<List<Map<String, Object>
if (headerRowIndex < firstRowNum) {
throw new IndexOutOfBoundsException(StrUtil.format("Header row index {} is lower than first row index {}.", headerRowIndex, firstRowNum));
} else if (headerRowIndex > lastRowNum) {
throw new IndexOutOfBoundsException(StrUtil.format("Header row index {} is greater than last row index {}.", headerRowIndex, firstRowNum));
throw new IndexOutOfBoundsException(StrUtil.format("Header row index {} is greater than last row index {}.", headerRowIndex, lastRowNum));
} else if (startRowIndex > lastRowNum) {
throw new IndexOutOfBoundsException(StrUtil.format("startRowIndex row index {} is greater than last row index {}.", startRowIndex, lastRowNum));
}
final int startRowIndex = Math.max(this.startRowIndex, firstRowNum);// 读取起始行包含
final int endRowIndex = Math.min(this.endRowIndex, lastRowNum);// 读取结束行包含

View File

@ -251,4 +251,21 @@ public class ExcelReadTest {
final ExcelReader reader = ExcelUtil.getReader(ResourceUtil.getStream("read_row_npe.xlsx"));
reader.readColumn(0, 1);
}
@Test
public void readIssueTest() {
//https://gitee.com/dromara/hutool/issues/I5OSFC
final ExcelReader reader = ExcelUtil.getReader(ResourceUtil.getStream("read.xlsx"));
final List<Map<String, Object>> read = reader.read(1,2,2);
for (Map<String, Object> map : read) {
Console.log(map);
}
//超出lastIndex 抛出相应提示startRowIndex row index 4 is greater than last row index 2.
//而非:Illegal Capacity: -1
try {
final List<Map<String, Object>> readGreaterIndex = reader.read(1,4,4);
} catch (Exception e) {
Console.log(e.toString());
}
}
}

Binary file not shown.