使用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);
}
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM