欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

Java使用easyExcel导出excel数据案例

时间:2021-05-27 08:42:46|栏目:JAVA代码|点击:

easyExcel简介:

Java领域解析、生成Excel比较有名的框架有Apache poi、jxl等。但他们都存在一个严重的问题就是非常的耗内存。如果你的系统并发量不大的话可能还行,但是一旦并发上来后一定会OOM或者JVM频繁的full gc。
easyExcel是阿里巴巴开源的一个excel处理框架,以使用简单、节省内存著称。
easyExcel采用一行一行的解析模式,并将一行的解析结果以观察者的模式通知处理
easyExcel能大大减少占用内存的主要原因是在解析Excel时没有将文件数据一次性全部加载到内存中,而是从磁盘上一行行读取数据,逐个解析。

1.导入依赖【poi不能低于3.17,不然可能会报错】

<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>poi</artifactId>
			<version>3.17</version>
		</dependency>
		<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>poi-ooxml</artifactId>
			<version>3.17</version>
		</dependency>

		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>easyexcel</artifactId>
			<version>1.1.2-beta5</version>
		</dependency>

2.控制层

<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>poi</artifactId>
			<version>3.17</version>
		</dependency>
		<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>poi-ooxml</artifactId>
			<version>3.17</version>
		</dependency>

		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>easyexcel</artifactId>
			<version>1.1.2-beta5</version>
		</dependency>

3.导出模型

package com.iflytek.edu.hnezxjgl.model;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.metadata.BaseRowModel;
import lombok.Data;

@Data
public class ExportModel extends BaseRowModel{

	 /**
   * 账号
   */
  @ExcelProperty(value = {"账号"}, index = 0)
  private String platformNum;
 
  /**
   * 姓名
   */
  @ExcelProperty(value = {"姓名"}, index = 1)
  private String name;
 
  /**
   * 身份证号
   */
  @ExcelProperty(value = {"身份证号"}, index = 2)
  private String idCardNum;
 
  /**
   * 性别
   */
  @ExcelProperty(value = {"性别"}, index = 3)
  private String sexName;
 
  /**
   * 年级
   */
  @ExcelProperty(value = {"年级"}, index = 4)
  private String gradeName;

	/**
	 * 班级
	 */
	@ExcelProperty(value = {"班级"}, index = 5)
	private String className;
  /**
   * 学费缴费状态名称
   */
  @ExcelProperty(value = "学费缴费状态名称",index = 6)
  private String studyFeeStatusName;
  /**
   * 书本费缴费状态名称
   */
  @ExcelProperty(value = "书本费缴费状态名称",index = 7)
  private String bookFeeStatusName;
  
}

4.几万条数据实现秒导

在这里插入图片描述

上一篇:Spring MVC过滤器-登录过滤的代码实现

栏    目:JAVA代码

下一篇:Java 对称加密几种算法分别实现

本文标题:Java使用easyExcel导出excel数据案例

本文地址:http://www.codeinn.net/misctech/129678.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有