zoukankan      html  css  js  c++  java
  • hutool读取Excel内容

    需要引入依赖

     <dependency>
                <groupId>cn.hutool</groupId>
                <artifactId>hutool-all</artifactId>
                <version>5.4.7</version>
            </dependency>
            <dependency>
                <groupId>org.apache.poi</groupId>
                <artifactId>poi</artifactId>
                <version>3.16</version>
            </dependency>
    
            <dependency>
                <groupId>org.apache.poi</groupId>
                <artifactId>poi-ooxml</artifactId>
                <version>3.16</version>
            </dependency>

    代码:

    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<List<Object>> read = excelReader.read(2, excelReader.getRowCount());
            for (List<Object> objects : read) {
         // 获取指定的的数据
    } } }
    踏踏实实的走,每一步都算数
  • 相关阅读:
    C#中Linq查询基本操作
    Python中的四种数据结构
    20200917练习题
    SRS搭建自己的直播、点播系统
    20200916练习题
    20200915练习题
    20200914练习题
    20200911练习题
    UTF-8最多编码字符数(最多可以容纳多少数量的字符)?
    k8s新手必看
  • 原文地址:https://www.cnblogs.com/keepstudy-xiahl/p/14249638.html
Copyright © 2011-2022 走看看