使用poi进行excel导入

进行信息表导入

/*
导入档案
*/
@RequestMapping("addArchives")
public String addArchives(MultipartFile files) throws IOException {
//解析excel----->档案的集合------>批量插入
InputStream is = files.getInputStream();
//excel对象读取excel文件流
HSSFWorkbook book=new HSSFWorkbook(is);
List<Archives> alist=new ArrayList<>();
//遍历工作薄
for (int i = 0; i <book.getNumberOfSheets() ; i++) {
HSSFSheet sheet = book.getSheetAt(i);
if(sheet==null){
continue;
}
//遍历行
for (int j = 0; j <sheet.getLastRowNum() ; j++) {
HSSFRow row = sheet.getRow(j+1);
if(row!=null){
Archives arc=new Archives();
arc.setDnum(row.getCell(0).getStringCellValue());
arc.setLandline(row.getCell(1).getStringCellValue());
arc.setSchool(row.getCell(2).getStringCellValue());
arc.setZhuanye(row.getCell(3).getStringCellValue());
arc.setSosperson(row.getCell(4).getStringCellValue());
arc.setBiyedate(row.getCell(5).getDateCellValue());
arc.setZzmm(row.getCell(6).getStringCellValue());
arc.setMinzu(row.getCell(7).getStringCellValue());
arc.setXueli(row.getCell(8).getStringCellValue());
arc.setEmail(row.getCell(9).getStringCellValue());
arc.setEmpFk((int)row.getCell(10).getNumericCellValue());
arc.setRemark(row.getCell(11).getStringCellValue());
arc.setBirdate(row.getCell(12).getDateCellValue());
alist.add(arc);
}
}

猜你喜欢

转载自www.cnblogs.com/meani/p/12628400.html