提示:本文介绍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