依赖
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.12</version>
</dependency>
controller
@PostMapping("/addlist")
@ResponseBody
public List<CommonDict> addlist( MultipartFile file) {
try {
Workbook workbook = Workbook.getWorkbook(file.getInputStream());
Sheet sheet = workbook.getSheet(0);
for (int i = 0; i < sheet.getRows(); i++) {
CommonDict commonDict = new CommonDict();
String code = sheet.getCell(0, i).getContents();
String name = sheet.getCell(1, i).getContents();
String sex = sheet.getCell(2, i).getContents();
commonDict.setDictCode(code);
commonDict.setDictName(name);
List<CommonDict> commonDicts = commonDictService.selectCommonDictByCode(sex);
if (commonDicts!=null&&commonDicts.size()>0){
if(commonDicts.get(0)!=null){
commonDict.setParentId( commonDicts.get(0).getId());
commonDict.setOrderNum(0);
commonDictService.insertCommonDict(commonDict);
}
}
}
return null;
} catch (IOException e) {
e.printStackTrace();
} catch (BiffException e) {
e.printStackTrace();
}
return null;
}
excel格式必须为xls!!!!!