GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - MatrixSeven/ExcelReads: ExcelReads(简单Excel通用读写器)

BranchesTags
Open more actions menu

Latest commit

 

History

64 Commits
64 Commits

Folders and files

NameName
Last commit message
Last commit date
src
src
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
Save.xlsx
Save.xlsx
 
 
SaveMap.xlsx
SaveMap.xlsx
 
 
UPDATELOG.MD
UPDATELOG.MD
 
 
jetbrains-variant-3.png
jetbrains-variant-3.png
 
 
pom.xml
pom.xml
 
 
write.png
write.png
 
 
关系(old).png
关系(old).png
 
 
关系(old_01).png
关系(old_01).png
 
 
关系.png
关系.png
 
 
实体类.png
实体类.png
 
 
引用.png
引用.png
 
 
效果_.png
效果_.png
 
 
测试.xls
测试.xls
 
 
测试.xlsx
测试.xlsx
 
 

Repository files navigation

ExcelReads(简单Excel通用读写器)

Apache License, Version 2.0, January 2004 Jenkins Status last_release language

ExcelReads是什么?

  • 这是一个通用的简单的Excel读取器
  • 支持自定义JavaBean实体读取和HashMap自动读取
  • 支持自定义扩展
  • 支持自定义Sheet范围,数据开始行数
  • 支持数据库查询直接导出Excel(Map/Object)
  • 支持正则过滤数据格式
  • JavaBean实体支持使用注解添加正则规则校验,HashMap支持数组规则校验
  • 依赖POI,使用Maven构建

在项目的pom文件增加下面内容,即可食用! Enjoy it!!!

<dependency>
  <groupId>com.github.matrixseven</groupId>
  <artifactId>ExcelReads</artifactId>
  <version>1.0.4</version>
</dependency>


更新日志详见:UpdateLogs.md

最近三次更新:

更新2019/12/2 

  • 替换导出方式
  • 增加 Create/CreateLoop[Map|Obj]
  • 更新顶层接口

更新2019/4/26 (诈尸更新)

  • 更加完善的类型推导,书写更方便(Great!!!)
  • 修复增加过滤列无法读取数据bug
  • 替换一些接口为Java8内置接口
  • 更流畅优雅的调用方法
  • 标注一些不建议使用的类/方法/属性

更新2017/01/11

  • 增加AnyCol来对应FilterCol方法,只保留AnyCol类列
  • 增加SetCellStyle,突破CellStyle绑定wk约束,链式设置列单元格风格(非常狗血)

其他

  • 自定义读取支持出简单的规范化数据格式,即典型的表头格式
  • 可以继承 WapperMap 和 WapperObj进行扩展
  • 直接使用ExcelFactory.getBeans进行获取,WapperObj则自己添加泛型
  • 注解Value对应列标题,Required对应正则,可自己写正则表达式或者直接使用RegHelper
  • 实体bean数据要比hashMap慢,7w条数据慢800ms,加入正则减慢速度(测试中加入了正则)

使用方法说明

  1. 本程序只能读取简单格式的xls/xlsx文件,文件布局如下(标准的行列结构):
标题1 标题2 标题3
foo foo foo
bar bar bar
baz baz baz

读取Excel

  • 喜大若奔(。・・)ノ Filter/Sort等lambda操作不用在声明类型(还是要写一个泛型)
    //CreateMapLoop 多sheet|isLoopSheet
    Map<String, Map<String, String>> maps = ExcelFactory.getMaps(filePath, it -> it.vocSize(1999)
            .title(2)
            .content(3)
            .isLoopSheet(true))
            .Filter(it -> it.get("在线人数").equals("43"))
            .CreateMapLoop();
    //CreateMap 单个
    List<Map<String, String>> maps2 = ExcelFactory.getMaps(filePath, it -> it.vocSize(1999)
            .title(2)
            .content(3))
            .Filter(it -> it.get("在线人数").equals("43"))
            .CreateMap();
    //Create Obj
    List<B> create = ExcelFactory.<B>getBeans(B.class, filePath, it -> it.title(2)
            .content(3)).Create();
    //CreateObjLoop
    String filePath2 = System.getProperty("user.dir").concat("/seven.xlsx");
    Map<String, List<A>> stringListMap = ExcelFactory.<A>getBeans(A.class, filePath2,
            it -> it.withConvert("姓名", ConvertTest.class)
                    .isLoopSheet(true)
                    .withConvert("姓名", f -> f.toString().concat("111111111")))
            .Process(a -> a.setA(a.getA() + "fuck"))
            .CreateObjLoop();

数据库导出自定义Bean类型写法(xxx.Class类型)

Result data=UNPOOLED_DATA_SOURCE.getConnection().prepareStatement("select * FROM  users_info limit 1000").executeQuery()
ExcelFactory.saveExcel(data,filePath,AS.class)
    .Filter(o->o.getA().length() > 3)
    .Flush();
    
  //ConvertName 转行列名  
ExcelFactory.saveExcel(ps.executeQuery()).SetPath("seven.xlsx")
    .Process(it->it.put("address",it.get("address").concat("seven")))
    .SetCellStyle("A", cellStyle -> cellStyle
                            .setFillPattern(FillPatternType.DIAMONDS)
                            .setAlignment(HorizontalAlignment.RIGHT)
                            .setFillForegroundColor(HSSFColor.WHITE.index)
                            .setBottomBorderColor(HSSFColor.RED.index)
                            .setFillBackgroundColor(HSSFColor.GOLD.index)
                            .setRightBorderColor(HSSFColor.INDIGO.index))
    .ConvertName("address","地址")
    .ConvertName("name","姓名")
    .Flush();

效果

ExcelReads

实体类截图

ExcelReads

继承关系

ExcelReads

引用关系

ExcelReads

写入效果

ExcelReads

  • 邮件([email protected])
  • QQ: 985390927
  • weibo: @Alden_情绪控
  • Blog: http://blog.52python.cn

Acknowledgement

!特别感谢 JetBrains 为开源项目提供免费的 IntelliJ IDEA 等 IDE 的授权

About

ExcelReads(简单Excel通用读写器)

Topics

excelexcelreaderexcelwriterpoitools

Resources

Readme
Apache-2.0 license
Activity

Stars

47 stars

Watchers

11 watching

Forks

25 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.