hutool读取Excel内容
需要引入依赖
cn.hutool hutool-all 5.4.7 org.apache.poi poi 3.16 org.apache.poi poi-ooxml 3.16
代码:
package com.java.test; import cn.hutool.poi.excel.ExcelReader; import cn.hutool.poi.excel.ExcelUtil; import org.apache.poi.util.IOUtils; import org.junit.Test; import org.springframework.mock.web.MockMultipartFile; import org.springframework.web.multipart.MultipartFile; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.util.List; /** * @author AiQ * @date 2021/1/8 * @describe: */ public class TestHutool { @Test public void test() throws Exception{ File file = new File("G:\\AiQ.xlsx"); FileInputStream input = new FileInputStream(file); MultipartFile multipartFile =new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(input)); // 1.获取上传文件输入流 InputStream inputStream = null; try{ inputStream = multipartFile.getInputStream(); }catch (Exception e){ } // 2.应用HUtool ExcelUtil获取ExcelReader指定输入流和sheet ExcelReader excelReader = ExcelUtil.getReader(inputStream, "代理"); // 可以加上表头验证 // 3.读取第二行到最后一行数据 List> read = excelReader.read(2, excelReader.getRowCount()); for (List