コード例 #1
0
 /** Excel文件下载处理 */
 @RequestMapping("/download")
 public ModelAndView downloanExcel() {
   List<UserInfo> list = new ArrayList<UserInfo>();
   UserInfo userInfo = new UserInfo();
   userInfo.setPassword("0000");
   userInfo.setUserName("sdfas");
   list.add(userInfo);
   list.add(userInfo);
   list.add(userInfo);
   list.add(userInfo);
   Map<String, List<UserInfo>> map = new HashMap<String, List<UserInfo>>();
   map.put("infoList", list);
   ExcelView ve = new ExcelView();
   return new ModelAndView(ve, map);
 }
コード例 #2
0
 /**
  * Excel文件上传处理
  *
  * @param file
  * @return
  */
 @RequestMapping("/upload")
 public ModelAndView uploadExcel(@RequestParam("file") MultipartFile file) {
   List<UserInfo> list = new ArrayList<UserInfo>();
   if (file.getOriginalFilename().contains("用户")) {
     try {
       Workbook wb = new HSSFWorkbook(file.getInputStream());
       Sheet sheet = wb.getSheetAt(0);
       for (int i = 1; i <= sheet.getLastRowNum(); i++) {
         Row row = sheet.getRow(i);
         UserInfo info = new UserInfo();
         info.setUserName(row.getCell(0).getStringCellValue());
         info.setPassword(row.getCell(1).getStringCellValue());
         list.add(info);
       }
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
   ModelAndView mav = new ModelAndView("content");
   mav.addObject("content", list.toString());
   return mav;
 }