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

在美国做网站如何接入收款工具百度快照客服

在美国做网站如何接入收款工具,百度快照客服,已经有域名 怎么做网站,在上海找工作用哪个招聘网好一、介绍 在上篇文章中,我们介绍了 apache poi 工具实现 excel 文件的导入导出。 本篇我们继续深入介绍另一款优秀的 excel 工具库:easypoi。 二、easypoi 以前的以前,有个大佬程序员,跳到一家公司之后就和业务人员聊上了&…

一、介绍

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

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

二、easypoi

以前的以前,有个大佬程序员,跳到一家公司之后就和业务人员聊上了,这些业务员对excel报表有着许许多多的要求,比如想要一个报表,他的表头是一个多行表头,过几天之后,他想要给这些表头添加样式,比如关键的数据标红,再过几天,他想要再末尾添加一条合计的数据,等等!

起初还好,都是copy、copy,之后发现系统中出现大量的重复代码,于是有一天真的忍受不了了,采用注解搞定来搞定这些定制化成程度高的逻辑,将公共化抽离出来,于是诞生了 easypoi!

easypoi 的底层也是基于 apache poi 进行深度开发的,它主要的特点就是将更多重复的工作,全部简单化,避免编写重复的代码!

下面,我们就一起来了解一下这款高大上的开源工具:easypoi

3.1、首先添加依赖包
<dependencies><dependency><groupId>cn.afterturn</groupId><artifactId>easypoi-base</artifactId><version>4.1.0</version></dependency><dependency><groupId>cn.afterturn</groupId><artifactId>easypoi-web</artifactId><version>4.1.0</version></dependency><dependency><groupId>cn.afterturn</groupId><artifactId>easypoi-annotation</artifactId><version>4.1.0</version></dependency>
</dependencies>
3.2、采用注解导出导入

easypoi 最大的亮点就是基于注解实体类来导出、导入excel,使用起来非常简单!

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

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

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

public static void main(String[] args) throws Exception {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);}//生成excel文档Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("用户","用户信息"),UserEntity.class, dataList);FileOutputStream fos = new FileOutputStream("/Users/hello/Documents/easypoi-user1.xls");workbook.write(fos);fos.close();
}

导出的文件预览如下:

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

public static void main(String[] args) {ImportParams params = new ImportParams();params.setTitleRows(1);params.setHeadRows(1);long start = new Date().getTime();List<StudentEntity> list = ExcelImportUtil.importExcel(new File("/Users/hello/Documents/easypoi-user1.xls"),UserEntity.class, params);System.out.println(new Date().getTime() - start);System.out.println(JSONArray.toJSONString(list));
}

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

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

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

  • 自定义数据导出 excel
public static void main(String[] args) throws Exception {//封装表头List<ExcelExportEntity> entityList = new ArrayList<ExcelExportEntity>();entityList.add(new ExcelExportEntity("姓名", "name"));entityList.add(new ExcelExportEntity("年龄", "age"));ExcelExportEntity entityTime = new ExcelExportEntity("操作时间", "time");entityTime.setFormat("yyyy-MM-dd HH:mm:ss");entityTime.setWidth(20.0);entityList.add(entityTime);//封装数据体List<Map<String, Object>> dataList = new ArrayList<>();for (int i = 0; i < 10; i++) {Map<String, Object> userEntityMap = new HashMap<>();userEntityMap.put("name", "张三" + i);userEntityMap.put("age", 20 + i);userEntityMap.put("time", new Date(System.currentTimeMillis() + i));dataList.add(userEntityMap);}//生成excel文档Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("学生","用户信息"), entityList, dataList);FileOutputStream fos = new FileOutputStream("/Users/panzhi/Documents/easypoi-user2.xls");workbook.write(fos);fos.close();
}
  • 导入 excel
public static void main(String[] args) {ImportParams params = new ImportParams();params.setTitleRows(1);params.setHeadRows(1);long start = new Date().getTime();List<Map<String, Object>> list = ExcelImportUtil.importExcel(new File("/Users/panzhi/Documents/easypoi-user2.xls"),Map.class, params);System.out.println(new Date().getTime() - start);System.out.println(JSONArray.toJSONString(list));
}

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

三、小结

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

四、参考

1、apache poi - 接口文档

2、easypoi - 接口文档

3、easyexcel - 接口文档

写到最后

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

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

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

http://www.tj-hxxt.cn/news/77169.html

相关文章:

  • 单位网站制作费用报价单百度一下首页网页百度
  • 个人网站备案多少钱小学生班级优化大师
  • html做网站实战教程百度搜索关键词热度
  • 环保网站 怎么做中国疫情今天最新消息
  • b2b分为哪四种模式seo综合查询国产
  • 网站建设seo优化推广昆山seo网站优化软件
  • 南京专业网站制作网站如何优化排名
  • 开发app需要的技术广州谷歌seo公司
  • 番禺大石做网站推广seo是什么意思
  • 网站建设合同服务内容西安网站制作公司
  • 网站建设咨询话术技巧中国免费域名注册平台
  • 企业网站管理系统演示平台网络推广和网站推广平台
  • java做网站用什么做seo专业术语
  • wordpress英文意思广州市口碑seo推广
  • 非洲做网站用哪里服务器好互联网营销渠道有哪些
  • php网站开发实例教程 pdf同城推广引流平台
  • 长宁区企业网站建设河北疫情最新情况
  • 衡阳网站建设 千度网络万网域名注册信息查询
  • 盱眙有做公司网站的吗百度竞价推广效果好吗
  • 武汉营销型网站建设seo搜索引擎优化薪资水平
  • 提供网站建设工具的品牌如何建立网站平台的步骤
  • 信誉好的营销网站建设seo优化裤子关键词
  • 兰州东方商易文化传播有限责任公司百度seo关键词排名查询
  • 用笔记本做网站服务器郑州纯手工seo
  • dnf做任务解制裁的网站seo外推
  • 外贸企业网站模板建设可以吗站长权重
  • 房产做网站是什么意思网络营销推广技术
  • 太原优化型网站建设百度网站名称及网址
  • wordpress二次元动漫seo网站优化师
  • 建设嫖客网站推广软文范文