├── README.md
├── easyexcel-plus-adapter
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── gongbo
│ │ └── excel
│ │ └── adapter
│ │ └── easyexcel
│ │ ├── EasyExcelAdapter.java
│ │ ├── ImportReadListener.java
│ │ ├── config
│ │ └── EasyExcelAdapterConfig.java
│ │ ├── converter
│ │ ├── DefaultEnumConvert.java
│ │ ├── ExcelValue.java
│ │ ├── LocalDateConverter.java
│ │ ├── LocalDateTimeConverter.java
│ │ └── LocalTimeConverter.java
│ │ └── overides
│ │ └── ExcelWriteFillExecutor.java
│ └── resources
│ └── META-INF
│ └── spring.factories
├── easyexcel-plus-boot-starter-test
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── gongbo
│ │ └── excel
│ │ └── example
│ │ ├── ServerApplication.java
│ │ ├── config
│ │ ├── EasyExcelConfig.java
│ │ ├── EasyExcelPlusConfig.java
│ │ ├── SwaggerConfig.java
│ │ └── WebConverters.java
│ │ ├── constants
│ │ └── GenderEnum.java
│ │ ├── controller
│ │ ├── ExportTestController.java
│ │ └── ImportControllerTest.java
│ │ ├── result
│ │ ├── Result.java
│ │ └── ResultCode.java
│ │ └── view
│ │ └── ExportDemoView.java
│ └── resources
│ ├── application.yml
│ └── templates
│ ├── template-formula.xls
│ ├── template-import.xlsx
│ ├── template-much-sheet.xlsx
│ ├── template-simply.xlsx
│ └── template-single-sheet.xlsx
├── easyexcel-plus-boot-starter
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── gongbo
│ │ └── excel
│ │ └── EasyExcelPlusConfiguration.java
│ └── resources
│ └── META-INF
│ └── spring.factories
├── easyexcel-plus-common
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── gongbo
│ └── excel
│ └── common
│ ├── adapter
│ └── Adapter.java
│ ├── enums
│ └── ExcelType.java
│ └── utils
│ ├── BeanMap.java
│ ├── CollectionUtil.java
│ ├── ReflectUtil.java
│ ├── ResponseUtils.java
│ ├── StringPool.java
│ ├── StringUtil.java
│ ├── TemplateUtils.java
│ ├── Times.java
│ ├── Utils.java
│ └── WebUtils.java
├── easyexcel-plus-export
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── gongbo
│ └── excel
│ └── export
│ ├── adapter
│ ├── ExportAdapter.java
│ └── ExportAdapters.java
│ ├── advise
│ └── ExportAdvise.java
│ ├── annotations
│ ├── Export.java
│ └── Exports.java
│ ├── config
│ ├── ExportConfig.java
│ └── ExportProperties.java
│ ├── constants
│ └── ExportExcelType.java
│ ├── core
│ ├── ExportContextHolder.java
│ ├── ExportHandlers.java
│ ├── ExportProxy.java
│ ├── lifecycle
│ │ ├── AbstractExportLifeCycle.java
│ │ ├── DefaultExportLifecycle.java
│ │ └── ExportLifecycle.java
│ └── resulthandler
│ │ ├── DefaultResultHandler.java
│ │ └── ResultHandler.java
│ ├── custom
│ ├── ExportDataConvert.java
│ ├── FieldFilter.java
│ ├── FileNameConvert.java
│ └── defaults
│ │ ├── DefaultExportDataConvert.java
│ │ ├── DefaultFieldFilter.java
│ │ └── DefaultFileNameConvert.java
│ ├── entity
│ ├── ExportContext.java
│ ├── ExportFieldInfo.java
│ └── ExportFillData.java
│ ├── exception
│ ├── ExportFailedException.java
│ ├── FillKeyNotFoundException.java
│ └── NotSupportExportException.java
│ ├── param
│ └── ExportParam.java
│ └── utils
│ ├── ExportFormulas.java
│ └── ExportUtils.java
├── easyexcel-plus-import
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── gongbo
│ └── excel
│ └── imports
│ ├── adapter
│ ├── ImportAdapter.java
│ └── ImportAdapters.java
│ ├── advise
│ └── ImportAdvise.java
│ ├── annotations
│ ├── Import.java
│ └── ImportTarget.java
│ ├── config
│ ├── ImportConfig.java
│ ├── ImportMappingJackson2HttpMessageConverter.java
│ └── ImportProperties.java
│ ├── core
│ ├── ImportContextHolder.java
│ ├── ImportProxy.java
│ └── lifecycle
│ │ ├── DefaultImportLifecycle.java
│ │ └── ImportLifecycle.java
│ ├── entity
│ └── ImportContext.java
│ ├── exception
│ ├── ImportFailedException.java
│ └── NotSupportImportException.java
│ ├── param
│ └── ImportParam.java
│ └── utils
│ └── ImportUtils.java
├── easyexcel-plus
└── pom.xml
├── images
└── img.png
├── img.png
├── img_1.png
└── pom.xml
/README.md:
--------------------------------------------------------------------------------
1 | # EasyExcelPlus
2 |
3 |
4 | 为简化开发工作、提高生产率而生
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | # 简介
18 |
19 | 导入、导出通用工具包 - 简化导入,导出开发(注意,与easyexcel不是同一个作者,easyexcel作者最新项目为fastexcel)
20 |
21 |
22 | 技术讨论 QQ 群 : 779290098
23 |
24 | # 优点 | Advantages
25 |
26 | - **易使用**:只需极少的配置,便可接入
27 | - **更简洁**:通过在原有的查询(批量新增)接口上添加相关注解即可实现导出(导入)功能,不需要为导出单独写一份代码,直接复用相应的查询接口即可,开发更简单,维护更方便
28 | - **更规范**:查询与导出(批量新增与导入)使用同一请求地址,你只需要知道查询接口请求地址,便能进行导出
29 | - **损耗小**:对使用性能几乎没有影响
30 | - **可扩展**:默认已支持使用阿里EasyExcel进行导入、导出,你还可以通过添加适配器接入的方式使用其他导入、导出工具
31 |
32 | # Latest Version: [](https://search.maven.org/search?q=g:io.github.gongbox%20a:easyexcel-plus*)
33 |
34 | ``` xml
35 |
36 | io.github.gongbox
37 | easyexcel-plus-boot-starter
38 | Latest Version
39 |
40 | ```
41 | ## 使用示例:
42 | 下面是一个普通查询接口:
43 | ```java
44 | @GetMapping(value = "test-normal")
45 | public Result> testNormal() {
46 | return Result.success(ExportDemoView.data());
47 | }
48 | ```
49 | 返回数据如下:
50 | > 演示地址:http://8.129.7.25/export/test-normal
51 |
52 | 若要实现导出excel,只需要在接口上增加注解@Export即可,如下所示:
53 | ```java
54 | @GetMapping(value = "test-normal")
55 | @Export
56 | public Result> testNormal() {
57 | return Result.success(ExportDemoView.data());
58 | }
59 | ```
60 | 添加该注解后,接口便同时支持查询、导出,不影响原有的查询。若要导出,则只需要添加请求参数export=excel即可,此时导出数据与查询结果一致,如下所示:
61 | > 演示地址(请复制地址到浏览器地址栏,按回车健访问):http://8.129.7.25/export/test-normal?export=excel
62 |
63 | ## 更多示例
64 | EasyExcelPlus支持多种多样的自定义配置,比如设置导出文件名、文件格式,模版导出,导出数据转换等等。
65 |
66 | 查看示例工程源码,请前往:https://github.com/gongbox/easyexcel-plus-example
67 |
68 | ### 环境说明
69 | - 模型类:
70 | ```java
71 | @Data
72 | @ColumnWidth(12)
73 | @ContentRowHeight(18)
74 | public class ExportDemoView {
75 |
76 | @ExcelProperty("文本")
77 | private String text = RandomUtil.randomString(8);
78 |
79 | @ExcelProperty("整数")
80 | private Integer integerValue = RandomUtil.randomInt(10000);
81 |
82 | @ExcelProperty("浮点数")
83 | private Float floatValue = (float) RandomUtil.randomDouble(-10000, 10000);
84 |
85 | @ExcelProperty("长浮点数")
86 | private Double doubleValue = RandomUtil.randomDouble(-10000, 10000);
87 |
88 | @ExcelProperty("定点数")
89 | private BigDecimal bigDecimal = RandomUtil.randomBigDecimal(BigDecimal.valueOf(10_000));
90 |
91 | @ExcelProperty("日期")
92 | private LocalDate localDate = LocalDate.now();
93 |
94 | @ExcelProperty("日期时间")
95 | @ColumnWidth(20)
96 | private LocalDateTime localDateTime = LocalDateTime.now();
97 |
98 | @ExcelProperty("时间")
99 | @ColumnWidth(20)
100 | private Date date = new Date();
101 |
102 | @ExcelProperty(value = "性别", converter = DefaultEnumConvert.class)
103 | private GenderEnum gender = GenderEnum.valueOf(RandomUtil.randomInt(3));
104 |
105 | public static List data() {
106 | return Stream.generate(ExportDemoView::new)
107 | .limit(RandomUtil.randomInt(1, 20))
108 | .collect(Collectors.toList());
109 | }
110 | }
111 | ```
112 | - 配置类:
113 | ```java
114 | @Configuration
115 | public class EasyExcelPlusConfig {
116 |
117 | @Bean
118 | public ResultHandler resultBuilder() {
119 | return new DefaultResultHandler() {
120 | @Override
121 | public Class> resultClass() {
122 | return Result.class;
123 | }
124 | @Override
125 | public Object getResultData(Object result) {
126 | if (result instanceof Result) {
127 | return ((Result>) result).getData();
128 | }
129 | return super.getResultData(result);
130 | }
131 | };
132 | }
133 | }
134 | ```
135 | - 配置文件:
136 | ```yaml
137 | spring:
138 | application:
139 | name: export_demo
140 |
141 | server:
142 | port: 80
143 | #以下配置项可根据需要配置,或者不配置使用默认值即可
144 | easyexcel-plus:
145 | export:
146 | #默认导出Sheet名称,不配则取默认值:Sheet1
147 | default-sheet-name: Sheet1
148 | #模板文件路径,不配则取默认值:空
149 | template-dir: classpath:templates
150 | #默认导出文件格式,不配则取默认值:xlsx
151 | default-excel-type: xlsx
152 | #默认导出方式,不配则取默认值:easy_excel
153 | default-export-by: easy_excel
154 | import:
155 | #默认导入读取的Sheet名称,不配则取默认值:Sheet1
156 | default-sheet-name: Sheet1
157 | #模板文件路径,不配则取默认值:空
158 | template-dir: classpath:templates
159 | #默认导入方式,不配则取默认值:easy_excel
160 | default-import-by: easy_excel
161 | #读取excel超时时间(单位ms),不设置或设置为0时无读取时间限制
162 | read-timeout: 60000
163 | ```
164 | ### 使用
165 |
166 | - **导出-设置导出文件名称**
167 | ```java
168 | @GetMapping(value = "test-fileName")
169 | @Export(fileName = "文件名称")
170 | public Result> testFilename() {
171 | return Result.success(ExportDemoView.data());
172 | }
173 | ```
174 | >演示地址:http://8.129.7.25/export/test-fileName?export=excel
175 | - **导出-动态设置文件名称**
176 | ```java
177 | @GetMapping(value = "test-fileName-convert")
178 | @Export(fileNameConvert = CustomFileNameConvert.class)
179 | public Result> testFileNameConvert() {
180 | return Result.success(ExportDemoView.data());
181 | }
182 |
183 | public static class CustomFileNameConvert implements FileNameConvert {
184 | @Override
185 | public String apply(String fileName) {
186 | return LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE);
187 | }
188 | }
189 | ```
190 | >演示地址:http://8.129.7.25/export/test-fileName-convert?export=excel
191 |
192 | 或者
193 | ```java
194 | @GetMapping(value = "test-fileName-business")
195 | @Export
196 | public Result> testFileNameBusiness() {
197 | if (ExportContextHolder.isExportExcel()) {
198 | ExportContextHolder.getContext().setFileName("动态文件名称");
199 | }
200 | return Result.success(ExportDemoView.data());
201 | }
202 | ```
203 | >演示地址:http://8.129.7.25/export/test-fileName-business?export=excel
204 | - **导出-固定Sheet名称**
205 | ```java
206 | @GetMapping(value = "test-sheetName")
207 | @Export(sheetName = "Sheet0")
208 | public Result> testSheetName() {
209 | return Result.success(ExportDemoView.data());
210 | }
211 | ```
212 | >演示地址:http://8.129.7.25/export/test-sheetName?export=excel
213 | - **导出-动态设置Sheet名称**
214 | ```java
215 | @GetMapping(value = "test-sheetName-business")
216 | @Export
217 | public Result> testSheetNameBusiness() {
218 | if (ExportContextHolder.isExportExcel()) {
219 | ExportContextHolder.getContext().setSheetName("业务中修改Sheet名称");
220 | }
221 | return Result.success(ExportDemoView.data());
222 | }
223 | ```
224 | >演示地址:http://8.129.7.25/export/test-sheetName-business?export=excel
225 | - **导出到固定文件夹**
226 | ```java
227 | @GetMapping(value = "test-out-path")
228 | @Export(outputPath = "D:\\WorkDir\\temp\\file")
229 | public Result> testOutPath() {
230 | return Result.success(ExportDemoView.data());
231 | }
232 | ```
233 | >演示地址:http://8.129.7.25/export/test-out-path?export=excel
234 | - **导出-字段过滤**
235 | ```java
236 | @GetMapping(value = "test-filter")
237 | @Export(fieldFilter = CustomFieldFilter.class)
238 | public Result> testFilter() {
239 | return Result.success(ExportDemoView.data());
240 | }
241 |
242 | public static class CustomFieldFilter implements FieldFilter {
243 | @Override
244 | public boolean predict(Field field) {
245 | return RandomUtil.randomBoolean();
246 | }
247 | }
248 | ```
249 | >演示地址:http://8.129.7.25/export/test-filter?export=excel
250 | - **导出-设置导出文件格式**
251 | ```java
252 | @GetMapping(value = "test-excelType")
253 | @Export(excelType = ExcelType.XLS)
254 | public Result> testExcelType() {
255 | return Result.success(ExportDemoView.data());
256 | }
257 | ```
258 | >演示地址:http://8.129.7.25/export/test-excelType?export=excel
259 | - **导出-数据转换**
260 | ```java
261 | @GetMapping(value = "test-dataConvert")
262 | @Export(dataConvert = CustomExportDataConvert.class)
263 | public Result> testDataConvert() {
264 | return Result.success(ExportDemoView.data());
265 | }
266 |
267 | public static class CustomExportDataConvert implements ExportDataConvert {
268 | @Override
269 | public List> convert(ExportContext exportContext, Object data) {
270 | Result> responseEntity = (Result>) data;
271 | List list = (List) responseEntity.getData();
272 | for (int i = 0; i < 20; i++) {
273 | list.add(new ExportDemoView());
274 | }
275 | return list;
276 | }
277 | }
278 | ```
279 | >演示地址:http://8.129.7.25/export/test-dataConvert?export=excel
280 | - **导出-同一接口多种导出方式**
281 | ```java
282 | @GetMapping(value = "test-tag")
283 | @Export(tag = "xls", excelType = ExcelType.XLS)
284 | @Export(tag = "xlsx", excelType = ExcelType.XLSX)
285 | public Result> testTag() {
286 | return Result.success(ExportDemoView.data());
287 | }
288 | ```
289 | 同一接口可以添加多个注解,以实现支持多种导出,通过注解tag属性设置标签,导出时,需要使用参数export_tag指定标签。
290 | > 演示地址,导出XLS :http://8.129.7.25/export/test-tag?export=excel&export_tag=xls
291 |
292 | > 演示地址,导出XLSX:http://8.129.7.25/export/test-tag?export=excel&export_tag=xlsx
293 | - **导出-简单模版导出**
294 | ```java
295 | /**
296 | * 导出-简单模版导出
297 | */
298 | @GetMapping(value = "test-template-simple")
299 | @Export(template = "template-simply.xlsx")
300 | public Result> testTemplateSimple() {
301 | return Result.success(ExportDemoView.data());
302 | }
303 | ```
304 | >演示地址:http://8.129.7.25/export/test-template-simple?export=excel
305 | - **导出-模版导出(单个Sheet)**
306 | ```java
307 | @GetMapping(value = "test-template-single-sheet")
308 | @Export(template = "template-single-sheet.xlsx", dataConvert = TemplateSingleSheetDataConvert.class)
309 | public Result> testTemplateSingleSheet() {
310 | return Result.success(ExportDemoView.data());
311 | }
312 |
313 | public static class TemplateSingleSheetDataConvert implements ExportDataConvert {
314 | @Override
315 | public List> convert(ExportContext exportContext, Object data) {
316 | Result> responseEntity = (Result>) data;
317 |
318 | ExportFillData exportFillData1 = ExportFillData.builder()
319 | .data(responseEntity.getData())
320 | .build();
321 |
322 | Map map = new HashMap<>();
323 | map.put("name", "名称");
324 | map.put("date", LocalDate.now().format(Times.Formatter.DEFAULT_DATE));
325 | ExportFillData exportFillData2 = ExportFillData.builder()
326 | .data(map)
327 | .build();
328 |
329 | return Lists.newArrayList(exportFillData1, exportFillData2);
330 | }
331 | }
332 | ```
333 | >演示地址:http://8.129.7.25/export/test-template-single-sheet?export=excel
334 | - **导出-模版导出(多个Sheet)**
335 | ```java
336 | @GetMapping(value = "test-template-much-sheet")
337 | @Export(template = "template-much-sheet.xlsx", dataConvert = TemplateMuchSheetDataConvert.class)
338 | public Result> testTemplateMuchSheet() {
339 | return Result.success(ExportDemoView.data());
340 | }
341 |
342 | public static class TemplateMuchSheetDataConvert implements ExportDataConvert {
343 | @Override
344 | public List> convert(ExportContext exportContext, Object data) {
345 | Result> responseEntity = (Result>) data;
346 |
347 | Map map = new HashMap<>();
348 |
349 | map.put("name", "名称");
350 | map.put("date", LocalDate.now().format(Times.Formatter.DEFAULT_DATE));
351 | ExportFillData exportFillData2 = ExportFillData.builder()
352 | .sheetName("Sheet1")
353 | .data(map)
354 | .build();
355 |
356 | ExportFillData exportFillData1 = ExportFillData.builder()
357 | .sheetName("Sheet2")
358 | .data(responseEntity.getData())
359 | .build();
360 |
361 | return Lists.newArrayList(exportFillData1, exportFillData2);
362 | }
363 | }
364 | ```
365 | >演示地址:http://8.129.7.25/export/test-template-much-sheet?export=excel
366 | - **导出-模版导出(公式)**
367 | ```java
368 | @GetMapping(value = "test-template-formula")
369 | @Export(template = "template-formula.xls", dataConvert = TemplateFormulaDataConvert.class)
370 | public Result> testTemplateFormula() {
371 | return Result.success(ExportDemoView.data());
372 | }
373 |
374 | public static class TemplateFormulaDataConvert implements ExportDataConvert {
375 | @Override
376 | public List> convert(ExportContext exportContext, Object data) {
377 | Result> responseEntity = (Result>) data;
378 | Collection> list = (Collection>) responseEntity.getData();
379 |
380 | ExportFillData exportFillData1 = ExportFillData.builder()
381 | .fillConfig(FillConfig.builder().forceNewRow(true).build())
382 | .data(new FillWrapper("data", list))
383 | .build();
384 |
385 | int start = 1;
386 | int end = start + (CollUtil.isEmpty(list) ? 0 : list.size() - 1);
387 |
388 | Map constantMap2 = new HashMap<>();
389 | constantMap2.put("data_end", end);
390 |
391 | ExportFillData exportFillData2 = ExportFillData.builder()
392 | .data(constantMap2)
393 | .build();
394 |
395 | return Lists.newArrayList(exportFillData1, exportFillData2);
396 | }
397 | }
398 | ```
399 | >演示地址:http://8.129.7.25/export/test-template-formula?export=excel
400 | - **导出-无包装类**
401 | ```java
402 | /**
403 | * 导出-简单导出(直接返回数组)
404 | */
405 | @GetMapping(value = "test-normal-array")
406 | @Export
407 | public ExportDemoView[] testNormalData() {
408 | return ExportDemoView.data().toArray(new ExportDemoView[0]);
409 | }
410 |
411 | /**
412 | * 导出-简单导出(直接返回集合)
413 | */
414 | @GetMapping(value = "test-normal-list")
415 | @Export
416 | public List testNormalList() {
417 | return ExportDemoView.data();
418 | }
419 |
420 | /**
421 | * 导出-简单导出(直接返回迭代器)
422 | */
423 | @GetMapping(value = "test-normal-iterable")
424 | @Export
425 | public Iterable testNormalIterable() {
426 | return ExportDemoView.data();
427 | }
428 | ```
429 | >演示地址:http://8.129.7.25/export/test-normal-array?export=excel
430 |
431 | >演示地址:http://8.129.7.25/export/test-normal-list?export=excel
432 |
433 | >演示地址:http://8.129.7.25/export/test-normal-iterable?export=excel
434 | - **导入-模板下载**
435 | ```java
436 | @GetMapping(value = "test-template")
437 | @Import(modelClass = ExportDemoView.class)
438 | public void testTemplate() {
439 | }
440 | ```
441 | >演示地址:
442 | > 导入-模版下载:http://8.129.7.25/import/test-template?import=template
443 | - **导入-自定义模版下载**
444 | ```java
445 | @GetMapping(value = "test-custom-template")
446 | @Import(modelClass = ExportDemoView.class, template = "template-import.xlsx", templateFilename = "自定义模板")
447 | public void testCustomTemplate() {
448 | }
449 | ```
450 | >演示地址:
451 | > 导入-自定义模版下载:http://8.129.7.25/import/test-custom-template?import=template
452 | - **导入-导入**
453 | ```java
454 | @PostMapping(value = "test-import")
455 | @Import
456 | public Result testImport(@RequestBody(required = false) ExportDemoView[] param) {
457 | return Result.success(param);
458 | }
459 | ```
460 | 
461 | >演示地址:
462 | > 导入-模版下载:http://8.129.7.25/import/test-import?import=excel
463 | - **导入-模板下载、数据导入**
464 | ```java
465 | @RequestMapping(value = "test-import-template", method = {RequestMethod.GET, RequestMethod.POST})
466 | @Import
467 | public Result testImportTemplate(@RequestBody(required = false) ExportDemoView[] param) {
468 | return Result.success(param);
469 | }
470 | ```
471 | 
472 | >演示地址: 导入-模版下载:http://8.129.7.25/import/test-import?import=template
473 |
474 | >演示地址: 导入-数组参数:http://8.129.7.25/import/test-import?import=excel
475 |
476 | # 期望 | Futures
477 |
478 | > 欢迎提出更好的意见,帮助完善 EasyExcelPlus
479 |
480 | # 版权 | License
481 |
482 | [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0)
483 |
484 | # 关注我 | About Me
485 |
486 | [简书](https://www.jianshu.com/u/9d2985772d9a)
487 |
488 |
--------------------------------------------------------------------------------
/easyexcel-plus-adapter/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | easyexcel-plus-parent
7 | io.github.gongbox
8 | 2.4.1
9 |
10 | 4.0.0
11 |
12 | easyexcel-plus-adapter
13 |
14 |
15 | 8
16 | 8
17 |
18 |
19 |
20 |
21 | io.github.gongbox
22 | easyexcel-plus-import
23 | ${project.parent.version}
24 | compile
25 |
26 |
27 | io.github.gongbox
28 | easyexcel-plus-export
29 | ${project.parent.version}
30 | compile
31 |
32 |
33 | io.github.gongbox
34 | easyexcel-plus-common
35 | ${project.parent.version}
36 | compile
37 |
38 |
39 | com.alibaba
40 | easyexcel
41 | compile
42 |
43 |
44 | org.springframework
45 | spring-aop
46 | compile
47 |
48 |
49 | org.aspectj
50 | aspectjweaver
51 | compile
52 |
53 |
54 |
55 |
56 |
57 |
58 | src/main/resources
59 |
60 | **/*
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/easyexcel-plus-adapter/src/main/java/com/gongbo/excel/adapter/easyexcel/EasyExcelAdapter.java:
--------------------------------------------------------------------------------
1 | package com.gongbo.excel.adapter.easyexcel;
2 |
3 | import com.alibaba.excel.EasyExcelFactory;
4 | import com.alibaba.excel.ExcelWriter;
5 | import com.alibaba.excel.annotation.ExcelProperty;
6 | import com.alibaba.excel.context.WriteContext;
7 | import com.alibaba.excel.enums.WriteTypeEnum;
8 | import com.alibaba.excel.exception.ExcelGenerateException;
9 | import com.alibaba.excel.read.builder.ExcelReaderBuilder;
10 | import com.alibaba.excel.read.builder.ExcelReaderSheetBuilder;
11 | import com.alibaba.excel.support.ExcelTypeEnum;
12 | import com.alibaba.excel.write.builder.ExcelWriterBuilder;
13 | import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder;
14 | import com.alibaba.excel.write.metadata.WriteSheet;
15 | import com.alibaba.excel.write.metadata.fill.FillConfig;
16 | import com.gongbo.excel.adapter.easyexcel.overides.ExcelWriteFillExecutor;
17 | import com.gongbo.excel.common.enums.ExcelType;
18 | import com.gongbo.excel.common.utils.CollectionUtil;
19 | import com.gongbo.excel.common.utils.ReflectUtil;
20 | import com.gongbo.excel.common.utils.StringPool;
21 | import com.gongbo.excel.common.utils.StringUtil;
22 | import com.gongbo.excel.export.adapter.ExportAdapter;
23 | import com.gongbo.excel.export.entity.ExportContext;
24 | import com.gongbo.excel.export.entity.ExportFieldInfo;
25 | import com.gongbo.excel.export.entity.ExportFillData;
26 | import com.gongbo.excel.export.exception.FillKeyNotFoundException;
27 | import com.gongbo.excel.imports.adapter.ImportAdapter;
28 | import com.gongbo.excel.imports.entity.ImportContext;
29 | import com.gongbo.excel.imports.utils.ImportUtils;
30 | import org.apache.poi.ss.usermodel.*;
31 |
32 | import java.io.IOException;
33 | import java.io.InputStream;
34 | import java.io.OutputStream;
35 | import java.lang.reflect.Field;
36 | import java.util.*;
37 | import java.util.concurrent.CompletableFuture;
38 | import java.util.concurrent.ExecutionException;
39 | import java.util.concurrent.TimeUnit;
40 | import java.util.concurrent.TimeoutException;
41 | import java.util.stream.Collectors;
42 |
43 | public class EasyExcelAdapter implements ExportAdapter, ImportAdapter {
44 |
45 | @Override
46 | public String name() {
47 | return "easy_excel";
48 | }
49 |
50 | private ExcelTypeEnum convert(ExcelType excelType) {
51 | if (excelType.getValue().equals(ExcelTypeEnum.XLS.getValue())) {
52 | return ExcelTypeEnum.XLS;
53 | } else if (excelType.getValue().equals(ExcelTypeEnum.XLSX.getValue())) {
54 | return ExcelTypeEnum.XLSX;
55 | } else {
56 | throw new IllegalArgumentException();
57 | }
58 | }
59 |
60 | @Override
61 | public Collection> read(ImportContext importContext, InputStream inputStream) throws IOException, ExecutionException, InterruptedException, TimeoutException {
62 | //导入数据临时存放容器
63 | Collection