zoukankan      html  css  js  c++  java
  • Springboot/SpringMvc 读取上传 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();
    }
  • 相关阅读:
    第二阶段冲刺—第三天
    团队测试计划
    第二阶段冲刺—第二天
    第二阶段冲刺—第一天
    评分表
    针对每个组建议的改进
    第二阶段团队绩效评分
    项目总结
    会议2.10
    会议2.9
  • 原文地址:https://www.cnblogs.com/laotan/p/9707705.html
Copyright © 2011-2022 走看看