Java接收解析excel方法以及注意事项

提示:本文介绍java接收解析excel


前言

提示:本文着重讲解java如何处理excel:

例如:本文从java接收excel,解析excel,以及业务场景中基于阻塞队列处理大批量的Excel。


提示:以下是本篇文章正文内容,下面案例可供参考

一、Java接收Excel

示例:pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的。

1.引入库

pom如下:

       <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.17</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.15</version>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.3</version>
        </dependency>
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.7.21</version>
        </dependency>

2.Controller层代码

提示: 本文MultipartFile接收,请求方式为form表单提交

       /**
     * 传入excel
     *
     * @return
     */
    @PostMapping(value = "/inputExcel", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @ApiOperation("传入excel")
    public R inputExcel(@RequestPart("file") MultipartFile file) {
   
        InputExcelDTO inputExcelDTO = new InputExcelDTO();
        inputExcelDTO.setFile(file);
        if (Objects.isNull(inputExcelDTO.getExcelName()) || Objects.isNull(inputExcelDTO.getFile())) {
   
            return R.failed("必填参数不可为空");
        }
        return excelService.inputExcel(inputExcelDTO);
    }

二、解析excel

1.将MultipartFile 转 File作为临时文件存储在本地,解析

代码如下:

工具类 :

package com.byt.form.convert.util;

import org.springframework.web.multipart.MultipartFile;

import java.io.*;
import java.util
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值