/**
* 读取上传 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();
}
相关文章:
- Springboot读取配置文件及自定义配置文件 2017-12-12
- node传统读取文件和promise,async await, 2018-05-11
- js 兼容IE9 无刷新文件上传 2018-03-09
- SpringMVC【参数绑定、数据回显、文件上传】 2018-03-17
- springboot读取自定义配置文件节点 2021-12-03
- node.js上传文件 2018-01-31
- ajax 上传文件 2018-03-14
- GitHub上传文件 2018-05-23