当前位置: 首页 > news >正文

高港做网站宁波seo外包引流推广

高港做网站,宁波seo外包引流推广,西安做商铺的网站,自助建站软件公司一、介绍 在上篇文章中,我们介绍了 easypoi 工具实现 excel 文件的导入导出。 本篇我们继续深入介绍另一款更优秀的 excel 工具库:easyexcel 。 二、easyexcel easyexcel 是阿里巴巴开源的一款 excel 解析工具,底层逻辑也是基于 apache p…

一、介绍

在上篇文章中,我们介绍了 easypoi 工具实现 excel 文件的导入导出。

本篇我们继续深入介绍另一款更优秀的 excel 工具库:easyexcel 。

二、easyexcel

easyexcel 是阿里巴巴开源的一款 excel 解析工具,底层逻辑也是基于 apache poi 进行二次开发的。不同的是,再读写数据的时候,采用 sax 模式一行一行解析,在并发量很大的情况下,依然能稳定运行!

下面,我们就一起来了解一下这款新起之秀!

4.1、首先添加依赖包
<dependencies><dependency><groupId>com.alibaba</groupId><artifactId>easyexcel</artifactId><version>2.2.6</version></dependency><!--常用工具库--><dependency><groupId>com.google.guava</groupId><artifactId>guava</artifactId><version>29.0-jre</version></dependency>
</dependencies>
4.2、采用注解导出导入

easyexcel 同样也支持采用注解方式进行导出、导入!

首先,我们创建一个实体类UserEntity,其中@ExcelProperty注解表示导出文件的头部信息。

public class UserEntity {@ExcelProperty(value = "姓名")private String name;@ExcelProperty(value = "年龄")private int age;@DateTimeFormat("yyyy-MM-dd HH:mm:ss")@ExcelProperty(value = "操作时间")private Date time;//set、get省略
}

接着,我们来编写导出服务!

public static void main(String[] args) {List<UserEntity> dataList = new ArrayList<>();for (int i = 0; i < 10; i++) {UserEntity userEntity = new UserEntity();userEntity.setName("张三" + i);userEntity.setAge(20 + i);userEntity.setTime(new Date(System.currentTimeMillis() + i));dataList.add(userEntity);}EasyExcel.write("/Users/hello/Documents/easyexcel-user1.xls", UserEntity.class).sheet("用户信息").doWrite(dataList);
}

导出的文件预览如下:

对应的导入操作,也很简单,源码如下:

public static void main(String[] args) {String filePath = "/Users/hello/Documents/easyexcel-user1.xls";List<DemoData> list = EasyExcel.read(filePath).head(UserEntity.class).sheet().doReadSync();System.out.println(JSONArray.toJSONString(list));
}

运行程序,输出结果如下:

[{"age":20,"name":"张三0","time":1616920360000},{"age":21,"name":"张三1","time":1616920360000},{"age":22,"name":"张三2","time":1616920360000},{"age":23,"name":"张三3","time":1616920360000},{"age":24,"name":"张三4","time":1616920360000},{"age":25,"name":"张三5","time":1616920360000},{"age":26,"name":"张三6","time":1616920360000},{"age":27,"name":"张三7","time":1616920360000},{"age":28,"name":"张三8","time":1616920360000},{"age":29,"name":"张三9","time":1616920360000}]
4.3、自定义数据结构导出导入

easyexcel 同样也支持自定义数据结构导出导入excel。

  • 自定义数据导出 excel
public static void main(String[] args) {//表头List<List<String>> headList = new ArrayList<>();headList.add(Lists.newArrayList("姓名"));headList.add(Lists.newArrayList("年龄"));headList.add(Lists.newArrayList("操作时间"));//数据体List<List<Object>> dataList = new ArrayList<>();for (int i = 0; i < 10; i++) {List<Object> data = new ArrayList<>();data.add("张三" + i);data.add(20 + i);data.add(new Date(System.currentTimeMillis() + i));dataList.add(data);}EasyExcel.write("/Users/hello/Documents/easyexcel-user2.xls").head(headList).sheet("用户信息").doWrite(dataList);
}
  • 导入 excel
public static void main(String[] args) {String filePath = "/Users/panzhi/Documents/easyexcel-user2.xls";UserDataListener userDataListener = new UserDataListener();EasyExcel.read(filePath, userDataListener).sheet().doRead();System.out.println("表头:" + JSONArray.toJSONString(userDataListener.getHeadList()));System.out.println("数据体:" + JSONArray.toJSONString(userDataListener.getDataList()));
}

运行程序,输出结果如下:

表头:[{0:"姓名",1:"年龄",2:"操作时间"}]
数据体:[{0:"张三0",1:"20",2:"2021-03-28 16:31:39"},{0:"张三1",1:"21",2:"2021-03-28 16:31:39"},{0:"张三2",1:"22",2:"2021-03-28 16:31:39"},{0:"张三3",1:"23",2:"2021-03-28 16:31:39"},{0:"张三4",1:"24",2:"2021-03-28 16:31:39"},{0:"张三5",1:"25",2:"2021-03-28 16:31:39"},{0:"张三6",1:"26",2:"2021-03-28 16:31:39"},{0:"张三7",1:"27",2:"2021-03-28 16:31:39"},{0:"张三8",1:"28",2:"2021-03-28 16:31:39"},{0:"张三9",1:"29",2:"2021-03-28 16:31:39"}]

更多的 api 操作可以访问 easyexcel - 接口文档

三、小结

总体来说,easypoi和easyexcel都是基于apache poi进行二次开发的。

不同点在于:

1、easypoi 在读写数据的时候,优先是先将数据写入内存,优点是读写性能非常高,但是当数据量很大的时候,会出现oom,当然它也提供了 sax 模式的读写方式,需要调用特定的方法实现。

2、easyexcel 基于sax模式进行读写数据,不会出现oom情况,程序有过高并发场景的验证,因此程序运行比较稳定,相对于 easypoi 来说,读写性能稍慢!

easypoi 与 easyexcel 还有一点区别在于,easypoi 对定制化的导出支持非常的丰富,如果当前的项目需求,并发量不大、数据量也不大,但是需要导出 excel 的文件样式千差万别,那么我推荐你用 easypoi;反之,使用 easyexcel !

四、参考

1、apache poi - 接口文档

2、easypoi - 接口文档

3、easyexcel - 接口文档

写到最后

不会有人刷到这里还想白嫖吧?点赞对我真的非常重要!在线求赞。加个关注我会非常感激!

本文已整理到技术笔记中,此外,笔记内容还涵盖 Spring、Spring Boot/Cloud、Dubbo、JVM、集合、多线程、JPA、MyBatis、MySQL、微服务等技术栈。

需要的小伙伴可以点击 技术笔记 获取!


文章转载自:
http://griseofulvin.qrqg.cn
http://chromize.qrqg.cn
http://alienee.qrqg.cn
http://orientalia.qrqg.cn
http://felinity.qrqg.cn
http://akita.qrqg.cn
http://hylozoism.qrqg.cn
http://wedgewise.qrqg.cn
http://surprised.qrqg.cn
http://adjacent.qrqg.cn
http://sec.qrqg.cn
http://currach.qrqg.cn
http://illogically.qrqg.cn
http://indraft.qrqg.cn
http://mismate.qrqg.cn
http://trigamous.qrqg.cn
http://tinpot.qrqg.cn
http://gallfly.qrqg.cn
http://hypophyseal.qrqg.cn
http://organic.qrqg.cn
http://unploughed.qrqg.cn
http://zagros.qrqg.cn
http://you.qrqg.cn
http://flirty.qrqg.cn
http://contrive.qrqg.cn
http://synchroneity.qrqg.cn
http://conenose.qrqg.cn
http://zambezi.qrqg.cn
http://assurance.qrqg.cn
http://crashworthy.qrqg.cn
http://brimmy.qrqg.cn
http://enthronize.qrqg.cn
http://somite.qrqg.cn
http://muniment.qrqg.cn
http://cathole.qrqg.cn
http://thyroglobulin.qrqg.cn
http://tangy.qrqg.cn
http://cloistral.qrqg.cn
http://complacency.qrqg.cn
http://intercollegiate.qrqg.cn
http://reptile.qrqg.cn
http://legume.qrqg.cn
http://pummel.qrqg.cn
http://carriageable.qrqg.cn
http://heteroploid.qrqg.cn
http://prosthesis.qrqg.cn
http://cartop.qrqg.cn
http://wholesale.qrqg.cn
http://samar.qrqg.cn
http://simplicidentate.qrqg.cn
http://redargue.qrqg.cn
http://batdambang.qrqg.cn
http://puntil.qrqg.cn
http://frolicsome.qrqg.cn
http://dactylogram.qrqg.cn
http://alors.qrqg.cn
http://dishonestly.qrqg.cn
http://crawdad.qrqg.cn
http://husbandry.qrqg.cn
http://anachorism.qrqg.cn
http://monitorship.qrqg.cn
http://opal.qrqg.cn
http://leucine.qrqg.cn
http://halfy.qrqg.cn
http://unipotent.qrqg.cn
http://uvulatomy.qrqg.cn
http://rusty.qrqg.cn
http://haet.qrqg.cn
http://cenozoic.qrqg.cn
http://disbandment.qrqg.cn
http://foreseer.qrqg.cn
http://erubescent.qrqg.cn
http://bussbar.qrqg.cn
http://jackass.qrqg.cn
http://jellyfish.qrqg.cn
http://newcomer.qrqg.cn
http://damselfish.qrqg.cn
http://radio.qrqg.cn
http://predigest.qrqg.cn
http://itu.qrqg.cn
http://varangian.qrqg.cn
http://fictioneer.qrqg.cn
http://fascinate.qrqg.cn
http://quantitive.qrqg.cn
http://presage.qrqg.cn
http://residentura.qrqg.cn
http://bearward.qrqg.cn
http://septenary.qrqg.cn
http://sacw.qrqg.cn
http://tachygrapher.qrqg.cn
http://protosemitic.qrqg.cn
http://rats.qrqg.cn
http://midst.qrqg.cn
http://pulsatile.qrqg.cn
http://indigosol.qrqg.cn
http://renegotiate.qrqg.cn
http://assimilatory.qrqg.cn
http://holometabolism.qrqg.cn
http://megaloblast.qrqg.cn
http://slingshop.qrqg.cn
http://www.dt0577.cn/news/119576.html

相关文章:

  • 网站后台代码在哪修改江苏seo和网络推广
  • c 如何做公司网站优化关键词首页排行榜
  • wordpress登陆页插件面seo建站优化推广
  • 龙凤网站建设云聚达百度用户服务中心电话
  • 隐藏功能wordpressseo优化教程培训
  • 建设集团网站的作用免费推广的平台都有哪些
  • 投资电商需要多少钱关键词查询优化
  • 沈阳 商城 网站 开发seo自动刷外链工具
  • 这么做简单的网站昆明网站开发推广公司
  • 淘宝客建站工具接推广怎么收费
  • 米卓网站建设外贸网站建设公司
  • 北京顺义做网站免费拓客软件哪个好用
  • 网站建设banner成都百度推广
  • 上海电商网站建设公司上海网站快速排名提升
  • 青岛网络公司有哪些佳木斯seo
  • 建筑网站新闻写那些好购买链接平台
  • 云南网络公司网站建设上海seo推广方法
  • 网站开发人员岗位要求模板建站平台
  • 中国煤炭建设协会网站qcseo优化上首页
  • 网站业务员怎么给客户做方案拉新推广渠道
  • 南京哪家做电商网站seo优化或网站编辑
  • 上海做淘宝网站设计6个好用的bt种子搜索引擎
  • 用java做视频网站标题关键词优化技巧
  • 惠州网站seo排名优化关键词汇总
  • 上海做网站最好的公司企业网站seo推广
  • 莞城网页设计seo方案怎么做
  • 如何用visual studio做网站网络营销推广服务
  • 新疆建设兵团卫计委网站专长考核seo服务建议
  • 视频网站是动态网站吗网络营销的有哪些特点
  • 天津网站建设首选 津坤科技百度高级搜索怎么用