导入Excel根据表头与注解名匹配

pull/67/MERGE
RuoYi 6 years ago
parent 999cd996fd
commit b1f4952cde

@ -8,7 +8,7 @@
<version>3.3</version> <version>3.3</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<packaging>war</packaging> <packaging>jar</packaging>
<artifactId>ruoyi-admin</artifactId> <artifactId>ruoyi-admin</artifactId>
<description> <description>

@ -136,17 +136,20 @@ public class ExcelUtil<T>
if (rows > 0) if (rows > 0)
{ {
// 定义一个map用于存放excel列的序号和field. // 定义一个map用于存放excel列的序号和field.
Map<String, Integer> cellMap = new HashMap<String, Integer>(); Map<String, Integer> cellMap = new HashMap<String, Integer>();
//获取表头 // 获取表头
Row heard = sheet.getRow(0); Row heard = sheet.getRow(0);
for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++) { for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++)
{
Cell cell = heard.getCell(i); Cell cell = heard.getCell(i);
if (StringUtils.isNotNull(cell != null)) { if (StringUtils.isNotNull(cell != null))
String value=this.getCellValue(heard, i).toString(); {
String value = this.getCellValue(heard, i).toString();
cellMap.put(value, i); cellMap.put(value, i);
} else { }
else
{
cellMap.put(null, i); cellMap.put(null, i);
} }
} }

Loading…
Cancel
Save