1.pom.xml文件的引入

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.example</groupId><artifactId>WorkForExcel</artifactId><version>1.0-SNAPSHOT</version><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target></properties><dependencies><!--读取excel文件--><dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>4.1.2</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>4.1.2</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>5.2.12.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>5.3.5</version></dependency><dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter</artifactId><version>RELEASE</version><scope>compile</scope></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.7.6</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>RELEASE</version><scope>compile</scope></dependency></dependencies></project>

2. java代码进行实现

import java.io.*;
import java.util.ArrayList;
import java.util.List;import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;import org.junit.jupiter.api.Test;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;/*** Created by Lenovo on 2018/1/21.*/
public class ReadExcelTools {@Testpublic void test(){File file = new File("C:\\Users\\24473\\Desktop\\住院收据1.xlsx");System.out.println(file.getName());//获取文件名称 gdwechat.xlsxList<Menu> all = new ArrayList<>();try(FileInputStream fileInputStream = new FileInputStream(file)){ExcelReader sheet1 = ExcelUtil.getReader(fileInputStream, "sheet1");System.out.println(sheet1);//cn.hutool.poi.excel.ExcelReader@28ec166esheet1.addHeaderAlias("费用金额(J)","parent_code");/*   sheet1.addHeaderAlias("费用金额(J)","formula_name");sheet1.addHeaderAlias("ICU(I)","formula_name");sheet1.addHeaderAlias("医保外扣除(Y)","formula_name");sheet1.addHeaderAlias("中高端不合理费用(Z)","formula_name");sheet1.addHeaderAlias("统筹报销(T)","formula_name");sheet1.addHeaderAlias("其他报销(Q)","formula_name");sheet1.addHeaderAlias("其他报销扣除(K)","formula_name");sheet1.addHeaderAlias("其他中高端扣费(G)","formula_name");sheet1.addHeaderAlias("非责任费用(F)","formula_name");sheet1.addHeaderAlias("ICU其他报销(X)","formula_name");sheet1.addHeaderAlias("ICU社保报销(S)","formula_name");*/all = sheet1.readAll(Menu.class);} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}/***[Menu(menuId=1, menuName=首页, menuUrl=/home, parentId=null, menuLevel=0, menuStatus=1, menuIcon=iconfont icon-index, menuIndex=1, urlName=null)]*/System.out.println(all);//打印读取的list数据System.out.println(all.size());//list条数 1}@Testpublic void test1(){File file = new File("C:\\Users\\24473\\Desktop\\工作簿2.xlsx");System.out.println(file.getName());//获取文件名称 gdwechat.xlsxList<Menu> all = new ArrayList<>();try(FileInputStream fileInputStream = new FileInputStream(file)){ExcelReader sheet1 = ExcelUtil.getReader(fileInputStream, "sheet1");System.out.println(sheet1);//cn.hutool.poi.excel.ExcelReader@28ec166esheet1.addHeaderAlias("菜单url","menuUrl");sheet1.addHeaderAlias("父菜单id","parentId");sheet1.addHeaderAlias("菜单级别","menuLevel");sheet1.addHeaderAlias("菜单状态","menuStatus");sheet1.addHeaderAlias("菜单icon","menuIcon");sheet1.addHeaderAlias("菜单排序","menuIndex");all = sheet1.readAll(Menu.class);} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}/***[Menu(menuId=1, menuName=首页, menuUrl=/home, parentId=null, menuLevel=0, menuStatus=1, menuIcon=iconfont icon-index, menuIndex=1, urlName=null)]*/System.out.println(all);//打印读取的list数据System.out.println(all.size());//list条数 1}}

3java实体类的创建:

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;import java.util.Date;
import java.util.List;@Data
//@Table(name="")
@AllArgsConstructor
@NoArgsConstructor
public class Menu {/* private Integer menuId;private String menuName;private String menuUrl;private Integer parentId;private Integer menuLevel;private Integer menuStatus;private String menuIcon;private Integer menuIndex;*///    @IdLong formula_id;
//    父公式代码String parent_code;String formula_name;      //          公式名称String formula_code;        //      公式代码Integer formula_type;       //      类型   0:非医疗收据   1:药房收据   2:门诊收据  3:住院收据String IS_EFFECT;                //是否有效String REMARK;            //描述Long QUALITY_ID;        //      属性IDString CRE_USER_ID;     //  创建人Date CRE_TIME;           //创建时间Date LAST_UPDATE_TIME;    //      最后更新时间String LAST_UPDATE_ID;    //  最后更新idLong ENTITY_ID;       //      实体id}

读取Excel数据到集合中相关推荐

  1. C#读取excel数据到datatable中

    1 DataTable dtGBPatient = new DataTable(); 2 3 string strConn;string excelName; 4 5 //注意:把一个excel文件看 ...

  2. python如何读取excel数据-python怎么读取excel中的数值

    最近测试过程中需要用到python读取excel用例数据,于是去了解和学习了下xlrd库,这里只记录使用过程中读取excel数据相关操作. 安装xlrd库(推荐学习:Python视频教程) 可以下载x ...

  3. R语言中读取excel数据的常用方式有哪些?

    R语言中读取excel数据的常用方式有哪些? 目录 R语言中读取excel数据的常用方式有哪些? R语言是解决什么问题的? R语言中读取excel数据的常用方式有哪些? R语言是解决什么问题的? R ...

  4. python读取excel送到网页_python怎么读取excel!怎么用python将excel数据写入网页中

    怎么用python将excel数据写入网页中 # 装 xlrd-0.9.2 xlutils-1.7.1 这两个模 from xlwt import Workbook, Formula import x ...

  5. python读excel中数据画图_python读取excel数据并且画图的实现示例

    一,要读取的数据的格式: 二,数据读取部分: b站视频参考:https://www.bilibili.com/video/BV14C4y1W7Nj?t=148 # 1930 workbook=xlrd ...

  6. java 读取Excel数据(POI)(一个sheet或者多个sheet)

    1.添加依赖 <dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml< ...

  7. android读取excel数据库,Android 读取Excel数据并保存在本地数据库

    在工作中遇到需要将Excel的数据读取出来并保存在本地数据库中的操作,数据如下: 图片.png 需要做以下准备: 读取Excel的jar包[文章末尾会分享该jar包] 保存数据的数据库框架,在这里我们 ...

  8. python读取excelsheet-一文看懂用Python读取Excel数据

    原标题:一文看懂用Python读取Excel数据 导读:现有的Excel分为两种格式:xls(Excel 97-2003)和xlsx(Excel 2007及以上). Python处理Excel文件主要 ...

  9. python读取excel某一列内容-Python读取Excel数据并根据列名取值

    一直想将自己接触到的东西梳理一遍,可就是迈不出第一步,希望从这篇总结开始不要再做行动的矮人了. 最近测试过程中需要用到python读取excel用例数据,于是去了解和学习了下xlrd库,这里只记录使用 ...

最新文章

  1. ​【特征工程】时序特征挖掘的奇技淫巧
  2. 剑指 Offer 24. 反转链表(C语言)
  3. 《Android群英传》读书笔记 (5) 第十一章 搭建云端服务器 + 第十二章 Android 5.X新特性详解 + 第十三章 Android实例提高...
  4. HMAC算法及其应用
  5. 防止表单重复提交的解决方案整理
  6. primefaces_PrimeFaces扩展中的全新JSF组件
  7. Android 系统(230)---OTA 软件包工具
  8. layer弹出层闪退_jQuery使用Layer弹出层插件闪退问题
  9. linux网站配置文件.htaccess伪静态转换到IIS web.config中
  10. matlab语音去噪_如何使用XAudioPro对音频去噪
  11. 浙江大学计算机科学与技术博士培养研究方向,浙江大学计算机科学技术学院博士研究生导师简介:王跃明...
  12. 一份完整的新媒体活动策划方案
  13. office 2007安装包
  14. Linux的安装教程 | 菜鸟教程
  15. 种业创新深圳品种 国稻种芯·中国水稻节:广东海水稻获成果
  16. JZOJ 5442 荒诞
  17. 母亲大人辛苦了(snowfall.jquery实现爱心掉落)
  18. 微博签到数据——北京、上海、昆明、深圳(2018-2022已更新完毕)
  19. 有关“夜壶冲”的由来
  20. [概率DP]相逢是温厚

热门文章

  1. Activiti使用教程
  2. MATLABR2016a安装与激活教程
  3. 基于51单片机的倒计时温度检测报警器
  4. J2EE技术简单介绍
  5. Day1作业2:多层菜单查询
  6. 专访 IJCAI 17 杰出青年科学家夏立荣博士:以人为本,是群体决策的必由之路
  7. OpenCV-Python图像的减法运算cv2.subtract函数详解以及和矩阵减法的差异对比
  8. keras中的Convolution1D
  9. 【Android】之【WebView】
  10. 初窥 fastlane 一键打包上传蒲公英平台和App Store