mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
#I5OSFC 修复,错误异常信息修改
This commit is contained in:
parent
f7ebc9f0fa
commit
a09dd3966b
@ -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);// 读取结束行(包含)
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
BIN
hutool-poi/src/test/resources/read.xlsx
Normal file
BIN
hutool-poi/src/test/resources/read.xlsx
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user