springboot 使用poi 导入excel

2024-01-09 12:24:30

示例

   public void uploadFile( HttpServletRequest request) {
        JSONObject jsonObject = new JSONObject();
        // 转型为MultipartHttpRequest:
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        // 获得文件:
        MultipartFile multipartFile = multipartRequest.getFile("file");
        if (multipartFile == null) {
            return jsonObject;
        }
        logger.info("上传文件, filename=" + multipartFile.getOriginalFilename());
        InputStream inputStream;
        try {
            inputStream = multipartFile.getInputStream();
            Workbook workbook = new XSSFWorkbook(inputStream);
            Sheet sheet = workbook.getSheetAt(0);
            Row row;
            for (int i = 1; i <= sheet.getLastRowNum(); i++) {
                row = sheet.getRow(i);
        	}
        } catch (Exception e) {
            logger.error("error:", e);
        }
    }

注:
1.sheet.getLastRowNum() 下标是从0开始

文章来源:https://blog.csdn.net/weixin_43833540/article/details/135454875
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。