/** * 讀取上傳 xls 內容返回 * @param file * @return */@RequestMapping(value = "/read.xls")@ResponseBodypublic String read(@RequestParam("file") MultipartFile file) { //判斷上傳的文件類型是否是圖片 int maxSize = 1024 * 1024 * 2; if (file == null || file.getSize()> maxSize){ object.put("msg","上傳文件 不能爲空/不能大於2M"); }else{ StringBuffer phones = new StringBuffer(); try { Workbook wb = WorkbookFactory.create(file.getInputStream()); Sheet sheet = wb.getSheetAt(0);// 第一個腳本下的 logger.info(sheet.toString()); sheet.forEach(e->{ e.forEach(e1->{ e1.setCellType(Cell.CELL_TYPE_STRING); phones.append(e1.getStringCellValue() + ","); }); }); } catch (Exception e) { e.printStackTrace(); } if(phones.length()>0){ phones.delete(phones.length()-1,phones.length()); } } return phones.toString();}