Skip to content

Commit c6cc206

Browse files
committed
???更新?
1 parent 08abea5 commit c6cc206

File tree

13 files changed

+572
-239
lines changed

13 files changed

+572
-239
lines changed

src/main/java/seven/ExcelFactory.java

Lines changed: 114 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
package seven;
22

3+
import org.apache.poi.ss.formula.functions.T;
34
import seven.callBack.PackageDataInterface;
5+
import seven.config.Config;
46
import seven.savewapper.SaveExcel;
57
import seven.savewapper.wapperRef.sysWppers.ResExportDBMap;
68
import seven.savewapper.wapperRef.sysWppers.ResExportDBObj;
79
import seven.savewapper.wapperRef.sysWppers.ResExportMap;
810
import seven.savewapper.wapperRef.sysWppers.ResExportObj;
9-
import seven.wapperInt.Wrapper;
11+
import seven.wapperInt.ReaderMap;
12+
import seven.wapperInt.ReaderObj;
1013
import seven.wapperInt.wapperRef.WrapperObj;
14+
import seven.wapperInt.wapperRef.sysWppers.ResWrapperMap;
15+
import seven.wapperInt.wapperRef.sysWppers.ResWrapperObj;
1116

17+
import java.io.File;
1218
import java.sql.ResultSet;
1319
import java.util.List;
1420
import java.util.Map;
21+
import java.util.function.Consumer;
1522

1623

1724
//=======================================================
@@ -29,6 +36,7 @@
2936
// ___`. | .'___
3037
// (______|______)
3138
//=======================================================
39+
3240
/**
3341
* @author Seven<p>
3442
* date 2016年6月4日-下午4:08:19
@@ -41,15 +49,116 @@ private ExcelFactory() {
4149

4250
/**
4351
* 读取Excel
52+
*
53+
* @param FilePath 路径
54+
* @param r 包装类
55+
* @return Wrapper
56+
* @throws Exception
57+
*/
58+
public static ReaderMap getMaps(String FilePath) throws Exception {
59+
return (ReaderMap) new ResWrapperMap(it->{}).init(FilePath);
60+
}
61+
62+
/**
63+
* 读取Excel
64+
*
65+
* @param FilePath 路径
66+
* @param r 包装类
67+
* @return Wrapper
68+
* @throws Exception
69+
*/
70+
public static <T> ReaderObj<T> getBeans(Class clazz,String FilePath) throws Exception {
71+
return new ResWrapperObj(clazz,it->{}).init(FilePath);
72+
}
73+
74+
/**
75+
* 读取Excel
76+
*
77+
* @param FilePath 路径
78+
* @param r 包装类
79+
* @return Wrapper
80+
* @throws Exception
81+
*/
82+
public static ReaderMap getMaps(String FilePath, Consumer<Config> config) throws Exception {
83+
return (ReaderMap) new ResWrapperMap(config).init(FilePath);
84+
}
85+
86+
/**
87+
* 读取Excel
88+
*
89+
* @param FilePath 路径
90+
* @param r 包装类
91+
* @return Wrapper
92+
* @throws Exception
93+
*/
94+
public static <T> ReaderObj<T> getBeans(Class clazz,String FilePath, Consumer<Config> config) throws Exception {
95+
return new ResWrapperObj(clazz, config).init(FilePath);
96+
}
97+
98+
/**
99+
* 读取Excel
100+
*
101+
* @param FilePath 路径
102+
* @param r 包装类
103+
* @return Wrapper
104+
* @throws Exception
105+
*/
106+
public static ReaderMap getMaps(File file) throws Exception {
107+
return (ReaderMap) new ResWrapperMap(it->{}).init(file);
108+
}
109+
110+
/**
111+
* 读取Excel
112+
*
113+
* @param FilePath 路径
114+
* @param r 包装类
115+
* @return Wrapper
116+
* @throws Exception
117+
*/
118+
public static <T> ReaderObj<T> getBeans(Class clazz,File file) throws Exception {
119+
return new ResWrapperObj(clazz,it->{}).init(file);
120+
}
121+
122+
/**
123+
* 读取Excel
124+
*
125+
* @param FilePath 路径
126+
* @param r 包装类
127+
* @return Wrapper
128+
* @throws Exception
129+
*/
130+
public static ReaderMap getMaps(File file, Consumer<Config> config) throws Exception {
131+
return (ReaderMap) new ResWrapperMap(config).init(file);
132+
}
133+
134+
/**
135+
* 读取Excel
136+
*
44137
* @param FilePath 路径
45138
* @param r 包装类
46139
* @return Wrapper
47140
* @throws Exception
48141
*/
49-
public static <T> Wrapper<T> getBeans(String FilePath, WrapperObj<T> r) throws Exception {
50-
return r.init(FilePath);
142+
public static <T> ReaderObj<T> getBeans(Class clazz,File file, Consumer<Config> config) throws Exception {
143+
return new ResWrapperObj(clazz, config).init(file);
51144
}
52145

146+
147+
148+
149+
150+
151+
152+
153+
154+
155+
156+
157+
158+
159+
160+
161+
53162
/**
54163
* 保存Excel
55164
*
@@ -58,12 +167,12 @@ public static <T> Wrapper<T> getBeans(String FilePath, WrapperObj<T> r) throws E
58167
* @return SaveExcel
59168
* @throws Exception
60169
*/
61-
public static <T> SaveExcel<T> saveExcel(List<? extends T> bean, String FilePath) throws Exception {
170+
public static <T> SaveExcel<T> saveExcel(List<? extends T> bean, String FilePath) throws Exception {
62171
if (bean.size() < 1) {
63172
throw new Exception("请传入数据");
64173
}
65174
if (bean.get(0) instanceof Map) {
66-
return (SaveExcel<T>) new ResExportMap((List<Map>)bean, FilePath);
175+
return (SaveExcel<T>) new ResExportMap((List<Map>) bean, FilePath);
67176
}
68177
return new ResExportObj(bean, FilePath);
69178
}

src/main/java/seven/ExcelSuperInterface.java

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,54 @@
1515
// (______|______)
1616
//=======================================================
1717

18+
import seven.callBack.DataFilterColumnInterface;
19+
import seven.callBack.DataFilterInterface;
20+
import seven.callBack.DataFilterProcessInterface;
21+
import seven.wapperInt.Wrapper;
22+
23+
import java.util.Comparator;
24+
import java.util.List;
25+
import java.util.function.Consumer;
26+
1827
/**
1928
* [Zhihu]https://www.zhihu.com/people/Sweets07
2029
* [Github]https://github.com/MatrixSeven
2130
* Created by seven on 2016/12/1.
2231
*/
23-
public interface ExcelSuperInterface {
32+
public interface ExcelSuperInterface<T,R> {
33+
34+
/**
35+
* 对要包装的数据进行过滤,对应实体Bean\n
36+
* 如果返回false将放弃此条数据
37+
*
38+
* @param filter {@link DataFilterInterface}
39+
* @return Wrapper
40+
*/
41+
T Filter(DataFilterInterface<? extends R> filter);
42+
43+
/**
44+
* 此处传入每一行打包好的数据。对应一个实体\n
45+
* 在process方法里可对属性进行处理加工
46+
*
47+
* @param process {@link DataFilterProcessInterface}
48+
* @return Wrapper
49+
*/
50+
T Process(DataFilterProcessInterface<? extends R> process);
51+
52+
/**
53+
* 对结果的List进行排序
54+
*
55+
* @param c
56+
* @return Wrapper
57+
*/
58+
T Sort(Comparator<? extends R> c);
59+
60+
/**
61+
* 此处过滤Excel的列数据(列名)\n
62+
* 如果加入后,将不对实体进行赋值
63+
*
64+
* @param consumer {@link DataFilterColumnInterface}
65+
*/
66+
T FilterCol(Consumer<List<String>> consumer);
2467

2568
}

src/main/java/seven/config/Config.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99
public class Config {
1010
private static final Logger logger= LoggerFactory.getLogger(Config.class);
1111

12-
private Integer titleRow = 1;
13-
private Integer contentRowStart = 2;
12+
private Integer titleRow = 0;
13+
private Integer contentRowStart = 1;
1414
private Integer contentRowEnd = null;
1515
private Boolean isLoopSheet = false;
1616
private Boolean errorLog = false;
17-
private Integer vocSize = 10000;
17+
private Integer vocSize = 128;
1818
@Deprecated
1919
private String[] require = null;
2020
private Integer startSheet = 0;
2121
private Integer endSheet = null;
22+
private Integer sheetIndex=-1;
23+
private String sheetName = null;
2224

2325
public Config() {
2426
}
@@ -77,6 +79,23 @@ public Config setErrorLog(Boolean errorLog) {
7779
return this;
7880
}
7981

82+
public Integer getSheetIndex() {
83+
return sheetIndex;
84+
}
85+
86+
public Config setSheetIndex(Integer sheetIndex) {
87+
this.sheetIndex = sheetIndex;
88+
return this;
89+
}
90+
91+
public String getSheetName() {
92+
return sheetName;
93+
}
94+
95+
public Config setSheetName(String sheetName) {
96+
this.sheetName = sheetName;
97+
return this;
98+
}
8099

81100
/**
82101
* 内容开始行号

src/main/java/seven/savewapper/SaveExcel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* [Github]https://github.com/MatrixSeven
3434
* Created by seven on 2016/11/30.
3535
*/
36-
public interface SaveExcel<T> extends ExcelSuperInterface {
36+
public interface SaveExcel<T> {
3737

3838
/**
3939
* 请使用Flush
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package seven.wapperInt;
2+
3+
//=======================================================
4+
// .----.
5+
// _.'__ `.
6+
// .--(^)(^^)---/!\
7+
// .' @ /!!!\
8+
// : , !!!!
9+
// `-..__.-' _.-\!!!/
10+
// `;_: `"'
11+
// .'"""""`.
12+
// /, ya ,\\
13+
// //狗神保佑\\
14+
// `-._______.-'
15+
// ___`. | .'___
16+
// (______|______)
17+
//=======================================================
18+
19+
import seven.ExcelSuperInterface;
20+
import seven.config.Config;
21+
22+
import java.util.List;
23+
import java.util.Map;
24+
import java.util.function.Consumer;
25+
26+
/**
27+
* @author Seven
28+
* FileName: WrapperObj.java
29+
* Created by Seven on 2019/11/28
30+
**/
31+
public interface ReaderMap extends ExcelSuperInterface<ReaderMap,Map> {
32+
33+
34+
List<Map<String, String>> CreateMap() throws Exception;
35+
36+
Map<String, Map<String, String>> CreateMapLoop() throws Exception;
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package seven.wapperInt;
2+
3+
//=======================================================
4+
// .----.
5+
// _.'__ `.
6+
// .--(^)(^^)---/!\
7+
// .' @ /!!!\
8+
// : , !!!!
9+
// `-..__.-' _.-\!!!/
10+
// `;_: `"'
11+
// .'"""""`.
12+
// /, ya ,\\
13+
// //狗神保佑\\
14+
// `-._______.-'
15+
// ___`. | .'___
16+
// (______|______)
17+
//=======================================================
18+
19+
import seven.ExcelSuperInterface;
20+
21+
import java.util.List;
22+
import java.util.Map;
23+
24+
25+
/**
26+
* @author Seven
27+
* FileName: WrapperObj.java
28+
* Created by Seven on 2019/11/28
29+
**/
30+
public interface ReaderObj<T> extends ExcelSuperInterface<ReaderObj<T>,T> {
31+
32+
33+
List<T> Create() throws Exception;
34+
35+
Map<String,List<T>> CreateObjLoop() throws Exception;
36+
37+
}

0 commit comments

Comments
 (0)