您的当前位置:首页正文

SpringbootSpringMvc读取上传xls文件内容

来源:画鸵萌宠网
SpringbootSpringMvc读取上传xls⽂件内容

/**

* 读取上传 xls 内容返回 * @param file * @return */

@RequestMapping(value = \"/read.xls\")@ResponseBody

public 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();}

因篇幅问题不能全部显示,请点此查看更多更全内容

Top