mirror of https://gitee.com/y_project/RuoYi.git
优化Excel导入增加空行判断
parent
3d12a776bc
commit
26e6bbcb6a
|
@ -185,7 +185,8 @@ public class ExcelUtil<T>
|
|||
throw new IOException("文件sheet不存在");
|
||||
}
|
||||
|
||||
int rows = sheet.getPhysicalNumberOfRows();
|
||||
// 获取最后一个非空行的行下标,比如总行数为n,则返回的为n-1
|
||||
int rows = sheet.getLastRowNum();
|
||||
|
||||
if (rows > 0)
|
||||
{
|
||||
|
@ -229,6 +230,11 @@ public class ExcelUtil<T>
|
|||
{
|
||||
// 从第2行开始取数据,默认第一行是表头.
|
||||
Row row = sheet.getRow(i);
|
||||
// 判断当前行是否是空行
|
||||
if (isRowEmpty(row))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
T entity = null;
|
||||
for (Map.Entry<Integer, Field> entry : fieldsMap.entrySet())
|
||||
{
|
||||
|
@ -1090,4 +1096,27 @@ public class ExcelUtil<T>
|
|||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否是空行
|
||||
*
|
||||
* @param row 判断的行
|
||||
* @return
|
||||
*/
|
||||
private boolean isRowEmpty(Row row)
|
||||
{
|
||||
if (row == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
for (int i = row.getFirstCellNum(); i < row.getLastCellNum(); i++)
|
||||
{
|
||||
Cell cell = row.getCell(i);
|
||||
if (cell != null && cell.getCellType() != CellType.BLANK)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue