Skip to content

Commit 7430611

Browse files
committed
合并dev,发布版本1.0.1,完善类型推导
1 parent 1c7572a commit 7430611

File tree

7 files changed

+224
-140
lines changed

7 files changed

+224
-140
lines changed

ExcelReads.jar

-13.3 MB
Binary file not shown.

README.md

Lines changed: 119 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,120 @@
1-
# ExcelReads(简单Excel通用读写器)
2-
3-
![Apache License, Version 2.0, January 2004](https://img.shields.io/github/license/apache/maven.svg?label=License)
4-
![Jenkins Status](https://img.shields.io/jenkins/s/https/builds.apache.org/job/maven-box/job/maven/job/master.svg?style=flat-square)
5-
6-
## ExcelReads是什么?
7-
* 这是一个通用的简单的Excel读取器
8-
* 支持自定义JavaBean实体读取和HashMap自动读取
9-
* 支持自定义扩展
10-
* 支持自定义Sheet范围,数据开始行数
11-
* 支持数据库查询直接导出Excel(Map/Object)
12-
* 支持正则过滤数据格式
13-
* JavaBean实体支持使用注解添加正则规则校验,HashMap支持数组规则校验
14-
* 依赖POI,使用Maven构建
15-
16-
## [更新日志详见:UpdateLogs.md](UPDATELOG.MD)
17-
###最近三次更新:
18-
19-
#### 更新2019/4/26 (诈尸更新)
20-
* 更加完善的类型推导,书写更方便(Great!!!)
21-
* 修复增加过滤列无法读取数据bug
22-
* 替换一些接口为Java8内置接口
23-
* 更流畅优雅的调用方法
24-
* 标注一些不建议使用的类/方法/属性
25-
26-
#### 更新2017/01/11
27-
* 增加AnyCol来对应FilterCol方法,只保留AnyCol类列
28-
* 增加SetCellStyle,突破CellStyle绑定wk约束,链式设置列单元格风格(非常狗血)
29-
30-
#### 更新2017/01/09
31-
* 增加SetPath方法,随时切换保存路径
32-
* 增加ConvertName方法,方便自定义Excel列名称
33-
* 增加Flush方法,不在建议使用~~Save(@Deprecated)~~方法进行保存输出
34-
* 增加SetOutputStream方法,可以放入自定义流,用于支持网页Response输出
35-
* 处理一些小bug,完善异常提示信息
36-
37-
### 其他
38-
* 自定义读取支持出简单的规范化数据格式,即典型的表头格式
39-
* 可以继承 WapperMap 和 WapperObj进行扩展
40-
* 直接使用ExcelFactory.getBeans进行获取,WapperObj则自己添加泛型
41-
* 注解Value对应列标题,Required对应正则,可自己写正则表达式或者直接使用RegHelper
42-
* 实体bean数据要比hashMap慢,7w条数据慢800ms,加入正则减慢速度(测试中加入了正则)
43-
44-
## 使用方法说明
45-
1. 本程序只能读取简单格式的xls/xlsx文件,文件布局如下(标准的行列结构):<br>
46-
47-
| 标题1 | 标题2 | 标题3 |
48-
|:-----:|:-----:|:-----:|
49-
|foo | foo | foo |
50-
|bar | bar | bar |
51-
|baz | baz | baz |
52-
53-
### 读取Excel
54-
55-
* 喜大若奔(。・・)ノ Filter/Sort等lambda操作不用在声明类型(~~还是要写一个泛型~~)
56-
```java
57-
//读取到Map类型
58-
//使用 .CreateMap(key_v) 生成Map<Key,Map>类型数据
59-
List<Map<String, String>> list = ExcelFactory.getBeans(filePath, WrapperFactory
60-
.MakeMap(it -> it.vocSize(1999).title(2).content(3)))
61-
.Filter(it -> !it.get("服务IP").contains("12"))
62-
.Process(it -> it.put("add", "这个是我增加的"))
63-
.FilterCol(df -> df.add("连接类型"))
64-
.CreateMap();
65-
66-
//读取到自定义JavaBean类型
67-
List<A> create = ExcelFactory.getBeans(filePath2, WrapperFactory.<A>MakeObj(it -> it.vocSize(1999)
68-
.title(0).content(1), A.class))
69-
.Filter(it -> it.getA().equals(""))
70-
.FilterCol(it -> it.add("1"))
71-
.Sort(Comparator.comparing(A::getA))
72-
.Create();
73-
```
74-
## 数据库导出自定义Bean类型写法(xxx.Class类型)
75-
```java
76-
Result data=UNPOOLED_DATA_SOURCE.getConnection().prepareStatement("select * FROM users_info limit 1000").executeQuery()
77-
ExcelFactory.saveExcel(data,filePath,AS.class)
78-
.Filter(o->o.getA().length() > 3)
79-
.Flush();
80-
81-
//ConvertName 转行列名
82-
ExcelFactory.saveExcel(ps.executeQuery()).SetPath("seven.xlsx")
83-
.Process(it->it.put("address",it.get("address").concat("seven")))
84-
.SetCellStyle("A", cellStyle -> cellStyle
85-
.setFillPattern(FillPatternType.DIAMONDS)
86-
.setAlignment(HorizontalAlignment.RIGHT)
87-
.setFillForegroundColor(HSSFColor.WHITE.index)
88-
.setBottomBorderColor(HSSFColor.RED.index)
89-
.setFillBackgroundColor(HSSFColor.GOLD.index)
90-
.setRightBorderColor(HSSFColor.INDIGO.index))
91-
.ConvertName("address","地址")
92-
.ConvertName("name","姓名")
93-
.Flush();
94-
```
95-
96-
## 效果
97-
![ExcelReads](效果.png)
98-
## 实体类截图
99-
![ExcelReads](实体类.png)
100-
## 继承关系
101-
![ExcelReads](关系.png)
102-
## 引用关系
103-
![ExcelReads](引用.png)
104-
## 写入效果
105-
![ExcelReads](write.png)
106-
107-
* 邮件(hacker.kill07@gmail.com)
108-
* QQ: 985390927
109-
* weibo: [@Alden_情绪控](http://weibo.com/Sweets07)
1+
# ExcelReads(简单Excel通用读写器)
2+
3+
![Apache License, Version 2.0, January 2004](https://img.shields.io/github/license/apache/maven.svg?label=License)
4+
![Jenkins Status](https://img.shields.io/jenkins/s/https/builds.apache.org/job/maven-box/job/maven/job/master.svg?style=flat-square)
5+
6+
## ExcelReads是什么?
7+
* 这是一个通用的简单的Excel读取器
8+
* 支持自定义JavaBean实体读取和HashMap自动读取
9+
* 支持自定义扩展
10+
* 支持自定义Sheet范围,数据开始行数
11+
* 支持数据库查询直接导出Excel(Map/Object)
12+
* 支持正则过滤数据格式
13+
* JavaBean实体支持使用注解添加正则规则校验,HashMap支持数组规则校验
14+
* 依赖POI,使用Maven构建
15+
16+
在项目的pom文件增加下面内容,即可食用! Enjoy it!!!
17+
```xml
18+
<dependency>
19+
<groupId>com.github.matrixseven</groupId>
20+
<artifactId>ExcelReads</artifactId>
21+
<version>1.0.1</version>
22+
</dependency>
23+
24+
```
25+
26+
## [更新日志详见:UpdateLogs.md](UPDATELOG.MD)
27+
###最近三次更新:
28+
29+
#### 更新2019/4/26 (诈尸更新)
30+
* 更加完善的类型推导,书写更方便(Great!!!)
31+
* 修复增加过滤列无法读取数据bug
32+
* 替换一些接口为Java8内置接口
33+
* 更流畅优雅的调用方法
34+
* 标注一些不建议使用的类/方法/属性
35+
36+
#### 更新2017/01/11
37+
* 增加AnyCol来对应FilterCol方法,只保留AnyCol类列
38+
* 增加SetCellStyle,突破CellStyle绑定wk约束,链式设置列单元格风格(非常狗血)
39+
40+
#### 更新2017/01/09
41+
* 增加SetPath方法,随时切换保存路径
42+
* 增加ConvertName方法,方便自定义Excel列名称
43+
* 增加Flush方法,不在建议使用~~Save(@Deprecated)~~方法进行保存输出
44+
* 增加SetOutputStream方法,可以放入自定义流,用于支持网页Response输出
45+
* 处理一些小bug,完善异常提示信息
46+
47+
### 其他
48+
* 自定义读取支持出简单的规范化数据格式,即典型的表头格式
49+
* 可以继承 WapperMap 和 WapperObj进行扩展
50+
* 直接使用ExcelFactory.getBeans进行获取,WapperObj则自己添加泛型
51+
* 注解Value对应列标题,Required对应正则,可自己写正则表达式或者直接使用RegHelper
52+
* 实体bean数据要比hashMap慢,7w条数据慢800ms,加入正则减慢速度(测试中加入了正则)
53+
54+
## 使用方法说明
55+
1. 本程序只能读取简单格式的xls/xlsx文件,文件布局如下(标准的行列结构):<br>
56+
57+
| 标题1 | 标题2 | 标题3 |
58+
|:-----:|:-----:|:-----:|
59+
|foo | foo | foo |
60+
|bar | bar | bar |
61+
|baz | baz | baz |
62+
63+
### 读取Excel
64+
65+
* 喜大若奔(。・・)ノ Filter/Sort等lambda操作不用在声明类型(~~还是要写一个泛型~~)
66+
```java
67+
//读取到Map类型
68+
//使用 .CreateMap(key_v) 生成Map<Key,Map>类型数据
69+
List<Map<String, String>> list = ExcelFactory.getBeans(filePath, WrapperFactory
70+
.MakeMap(it -> it.vocSize(1999).title(2).content(3)))
71+
.Filter(it -> !it.get("服务IP").contains("12"))
72+
.Process(it -> it.put("add", "这个是我增加的"))
73+
.FilterCol(df -> df.add("连接类型"))
74+
.CreateMap();
75+
76+
//读取到自定义JavaBean类型
77+
List<A> create = ExcelFactory.getBeans(filePath2, WrapperFactory.<A>MakeObj(it -> it.vocSize(1999)
78+
.title(0).content(1), A.class))
79+
.Filter(it -> it.getA().equals(""))
80+
.FilterCol(it -> it.add("1"))
81+
.Sort(Comparator.comparing(A::getA))
82+
.Create();
83+
```
84+
## 数据库导出自定义Bean类型写法(xxx.Class类型)
85+
```java
86+
Result data=UNPOOLED_DATA_SOURCE.getConnection().prepareStatement("select * FROM users_info limit 1000").executeQuery()
87+
ExcelFactory.saveExcel(data,filePath,AS.class)
88+
.Filter(o->o.getA().length() > 3)
89+
.Flush();
90+
91+
//ConvertName 转行列名
92+
ExcelFactory.saveExcel(ps.executeQuery()).SetPath("seven.xlsx")
93+
.Process(it->it.put("address",it.get("address").concat("seven")))
94+
.SetCellStyle("A", cellStyle -> cellStyle
95+
.setFillPattern(FillPatternType.DIAMONDS)
96+
.setAlignment(HorizontalAlignment.RIGHT)
97+
.setFillForegroundColor(HSSFColor.WHITE.index)
98+
.setBottomBorderColor(HSSFColor.RED.index)
99+
.setFillBackgroundColor(HSSFColor.GOLD.index)
100+
.setRightBorderColor(HSSFColor.INDIGO.index))
101+
.ConvertName("address","地址")
102+
.ConvertName("name","姓名")
103+
.Flush();
104+
```
105+
106+
## 效果
107+
![ExcelReads](效果.png)
108+
## 实体类截图
109+
![ExcelReads](实体类.png)
110+
## 继承关系
111+
![ExcelReads](关系.png)
112+
## 引用关系
113+
![ExcelReads](引用.png)
114+
## 写入效果
115+
![ExcelReads](write.png)
116+
117+
* 邮件(hacker.kill07@gmail.com)
118+
* QQ: 985390927
119+
* weibo: [@Alden_情绪控](http://weibo.com/Sweets07)
110120
* Blog: [http://blog.52python.cn](http://blog.52python.cn)

pom.xml

Lines changed: 88 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,55 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
33
<modelVersion>4.0.0</modelVersion>
4-
<groupId>Seven.ExcelReads</groupId>
4+
<groupId>com.github.matrixseven</groupId>
55
<artifactId>ExcelReads</artifactId>
6-
<packaging>pom</packaging>
7-
<version>0.0.1-SNAPSHOT</version>
6+
<packaging>jar</packaging>
7+
<version>1.0.1</version>
8+
<name>ExcelReads</name>
9+
<description>A ExcelReads Utils By Seven</description>
10+
<url>https://github.com/MatrixSeven/ExcelReads</url>
11+
<licenses>
12+
<license>
13+
<name>The Apache Software License, Version 2.0</name>
14+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
15+
<distribution>repo</distribution>
16+
</license>
17+
</licenses>
18+
<scm>
19+
<url>https://github.com/MatrixSeven/ExcelReads</url>
20+
<connection>https://github.com/MatrixSeven/ExcelReads.git</connection>
21+
<developerConnection>https://github.com/MatrixSeven/ExcelReads</developerConnection>
22+
</scm>
23+
<developers>
24+
<developer>
25+
<name>Seven</name>
26+
<email>hacker.kill07@gmail.com</email>
27+
<url>https://matrixseven.github.io</url>
28+
</developer>
29+
</developers>
30+
<distributionManagement>
31+
<snapshotRepository>
32+
<id>ossrh</id>
33+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
34+
</snapshotRepository>
35+
<repository>
36+
<id>ossrh</id>
37+
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
38+
</repository>
39+
</distributionManagement>
40+
841
<dependencies>
9-
<dependency>
10-
<groupId>org.apache.poi</groupId>
11-
<artifactId>poi</artifactId>
12-
<version>3.15</version>
13-
</dependency>
14-
<dependency>
15-
<groupId>org.apache.poi</groupId>
16-
<artifactId>poi-ooxml</artifactId>
17-
<version>3.15</version>
18-
</dependency>
42+
43+
<dependency>
44+
<groupId>org.apache.poi</groupId>
45+
<artifactId>poi</artifactId>
46+
<version>3.15</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.apache.poi</groupId>
50+
<artifactId>poi-ooxml</artifactId>
51+
<version>3.15</version>
52+
</dependency>
1953
<dependency>
2054
<groupId>junit</groupId>
2155
<artifactId>junit</artifactId>
@@ -38,6 +72,46 @@
3872
<target>1.8</target>
3973
</configuration>
4074
</plugin>
75+
<plugin>
76+
<groupId>org.apache.maven.plugins</groupId>
77+
<artifactId>maven-source-plugin</artifactId>
78+
<version>2.2.1</version>
79+
<executions>
80+
<execution>
81+
<id>attach-sources</id>
82+
<goals>
83+
<goal>jar-no-fork</goal>
84+
</goals>
85+
</execution>
86+
</executions>
87+
</plugin>
88+
<plugin>
89+
<groupId>org.apache.maven.plugins</groupId>
90+
<artifactId>maven-javadoc-plugin</artifactId>
91+
<version>2.9.1</version>
92+
<executions>
93+
<execution>
94+
<id>attach-javadocs</id>
95+
<goals>
96+
<goal>jar</goal>
97+
</goals>
98+
</execution>
99+
</executions>
100+
</plugin>
101+
<plugin>
102+
<groupId>org.apache.maven.plugins</groupId>
103+
<artifactId>maven-gpg-plugin</artifactId>
104+
<version>1.5</version>
105+
<executions>
106+
<execution>
107+
<id>sign-artifacts</id>
108+
<phase>verify</phase>
109+
<goals>
110+
<goal>sign</goal>
111+
</goals>
112+
</execution>
113+
</executions>
114+
</plugin>
41115
</plugins>
42116
</build>
43117
</project>

0 commit comments

Comments
 (0)