| @@ -6,14 +6,14 @@ EasyPoi Excel和 Word简易工具类 | |||||
| 就可以方便的写出Excel导出,Excel模板导出,Excel导入,Word模板导出,通过简单的注解和模板 | 就可以方便的写出Excel导出,Excel模板导出,Excel导入,Word模板导出,通过简单的注解和模板 | ||||
| 语言(熟悉的表达式语法),完成以前复杂的写法 | 语言(熟悉的表达式语法),完成以前复杂的写法 | ||||
| 官网: http://www.afterturn.cn/ | |||||
| 官网: http://opensource.afterturn.cn/ | |||||
| 邮箱: qrb.jueyue@foxmail.com | 邮箱: qrb.jueyue@foxmail.com | ||||
| QQ群: 1群 364192721(满) 2 群116844390 | QQ群: 1群 364192721(满) 2 群116844390 | ||||
| 开发者:魔幻之翼 xf.key@163.com | 开发者:魔幻之翼 xf.key@163.com | ||||
| Spring Boot 支持 https://gitee.com/lemur/easypoi-spring-boot-starter | Spring Boot 支持 https://gitee.com/lemur/easypoi-spring-boot-starter | ||||
| [官网](http://opensource.afterturn.cn) | |||||
| [官网](https://opensource.afterturn.cn) | |||||
| [VIP技术服务-账号忘了,还是QQ吧](https://lemur.taobao.com) | [VIP技术服务-账号忘了,还是QQ吧](https://lemur.taobao.com) | ||||
| @@ -24,7 +24,7 @@ Spring Boot 支持 https://gitee.com/lemur/easypoi-spring-boot-starter | |||||
| **开发指南** | **开发指南** | ||||
| **[http://opensource.afterturn.cn/doc/easypoi.html](http://opensource.afterturn.cn/doc/easypoi.html)** | |||||
| **[https://opensource.afterturn.cn/doc/easypoi.html](http://opensource.afterturn.cn/doc/easypoi.html)** | |||||
| [API文档](https://apidoc.gitee.com/lemur/easypoi/) | [API文档](https://apidoc.gitee.com/lemur/easypoi/) | ||||
| @@ -100,17 +100,17 @@ https://oss.sonatype.org/content/groups/public/ | |||||
| <dependency> | <dependency> | ||||
| <groupId>cn.afterturn</groupId> | <groupId>cn.afterturn</groupId> | ||||
| <artifactId>easypoi-base</artifactId> | <artifactId>easypoi-base</artifactId> | ||||
| <version>3.3.0</version> | |||||
| <version>4.0.0</version> | |||||
| </dependency> | </dependency> | ||||
| <dependency> | <dependency> | ||||
| <groupId>cn.afterturn</groupId> | <groupId>cn.afterturn</groupId> | ||||
| <artifactId>easypoi-web</artifactId> | <artifactId>easypoi-web</artifactId> | ||||
| <version>3.3.0</version> | |||||
| <version>4.0.0</version> | |||||
| </dependency> | </dependency> | ||||
| <dependency> | <dependency> | ||||
| <groupId>cn.afterturn</groupId> | <groupId>cn.afterturn</groupId> | ||||
| <artifactId>easypoi-annotation</artifactId> | <artifactId>easypoi-annotation</artifactId> | ||||
| <version>3.3.0</version> | |||||
| <version>4.0.0</version> | |||||
| </dependency> | </dependency> | ||||
| ``` | ``` | ||||
| @@ -4,7 +4,7 @@ | |||||
| <parent> | <parent> | ||||
| <groupId>cn.afterturn</groupId> | <groupId>cn.afterturn</groupId> | ||||
| <artifactId>easypoi</artifactId> | <artifactId>easypoi</artifactId> | ||||
| <version>4.0.0-SNAPSHOT</version> | |||||
| <version>4.0.0</version> | |||||
| </parent> | </parent> | ||||
| <artifactId>easypoi-annotation</artifactId> | <artifactId>easypoi-annotation</artifactId> | ||||
| <description>基础注解类,解耦合</description> | <description>基础注解类,解耦合</description> | ||||
| @@ -4,7 +4,7 @@ | |||||
| <parent> | <parent> | ||||
| <groupId>cn.afterturn</groupId> | <groupId>cn.afterturn</groupId> | ||||
| <artifactId>easypoi</artifactId> | <artifactId>easypoi</artifactId> | ||||
| <version>4.0.0-SNAPSHOT</version> | |||||
| <version>4.0.0</version> | |||||
| </parent> | </parent> | ||||
| <artifactId>easypoi-base</artifactId> | <artifactId>easypoi-base</artifactId> | ||||
| <dependencies> | <dependencies> | ||||
| @@ -1,8 +1,8 @@ | |||||
| package cn.afterturn.easypoi.csv; | package cn.afterturn.easypoi.csv; | ||||
| import cn.afterturn.easypoi.csv.entity.CsvImportParams; | import cn.afterturn.easypoi.csv.entity.CsvImportParams; | ||||
| import cn.afterturn.easypoi.csv.handler.ICsvSaveDataHandler; | |||||
| import cn.afterturn.easypoi.csv.imports.CsvImportService; | import cn.afterturn.easypoi.csv.imports.CsvImportService; | ||||
| import cn.afterturn.easypoi.handler.inter.IReadHandler; | |||||
| import java.io.InputStream; | import java.io.InputStream; | ||||
| import java.util.List; | import java.util.List; | ||||
| @@ -40,7 +40,7 @@ public final class CsvImportUtil { | |||||
| * @return | * @return | ||||
| */ | */ | ||||
| public static void importCsv(InputStream inputstream, Class<?> pojoClass, | public static void importCsv(InputStream inputstream, Class<?> pojoClass, | ||||
| CsvImportParams params, ICsvSaveDataHandler saveDataHandler) { | |||||
| new CsvImportService().readExcel(inputstream, pojoClass, params, saveDataHandler); | |||||
| CsvImportParams params, IReadHandler readHandler) { | |||||
| new CsvImportService().readExcel(inputstream, pojoClass, params, readHandler); | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,17 +0,0 @@ | |||||
| package cn.afterturn.easypoi.csv.handler; | |||||
| /** | |||||
| * 保存数据 | |||||
| * 鉴于CSV可能都是大数据,还是调用接口直接保存,避免内存占用 | |||||
| * | |||||
| * @author by jueyue on 18-10-3. | |||||
| */ | |||||
| public interface ICsvSaveDataHandler<T> { | |||||
| /** | |||||
| * 保存数据 | |||||
| * | |||||
| * @param t | |||||
| */ | |||||
| public void save(T t); | |||||
| } | |||||
| @@ -1,7 +1,6 @@ | |||||
| package cn.afterturn.easypoi.csv.imports; | package cn.afterturn.easypoi.csv.imports; | ||||
| import cn.afterturn.easypoi.csv.entity.CsvImportParams; | import cn.afterturn.easypoi.csv.entity.CsvImportParams; | ||||
| import cn.afterturn.easypoi.csv.handler.ICsvSaveDataHandler; | |||||
| import cn.afterturn.easypoi.excel.annotation.ExcelTarget; | import cn.afterturn.easypoi.excel.annotation.ExcelTarget; | ||||
| import cn.afterturn.easypoi.excel.entity.params.ExcelCollectionParams; | import cn.afterturn.easypoi.excel.entity.params.ExcelCollectionParams; | ||||
| import cn.afterturn.easypoi.excel.entity.params.ExcelImportEntity; | import cn.afterturn.easypoi.excel.entity.params.ExcelImportEntity; | ||||
| @@ -11,6 +10,7 @@ import cn.afterturn.easypoi.excel.imports.base.ImportBaseService; | |||||
| import cn.afterturn.easypoi.exception.excel.ExcelImportException; | import cn.afterturn.easypoi.exception.excel.ExcelImportException; | ||||
| import cn.afterturn.easypoi.exception.excel.enums.ExcelImportEnum; | import cn.afterturn.easypoi.exception.excel.enums.ExcelImportEnum; | ||||
| import cn.afterturn.easypoi.handler.inter.IExcelModel; | import cn.afterturn.easypoi.handler.inter.IExcelModel; | ||||
| import cn.afterturn.easypoi.handler.inter.IReadHandler; | |||||
| import cn.afterturn.easypoi.util.PoiPublicUtil; | import cn.afterturn.easypoi.util.PoiPublicUtil; | ||||
| import cn.afterturn.easypoi.util.PoiReflectorUtil; | import cn.afterturn.easypoi.util.PoiReflectorUtil; | ||||
| import cn.afterturn.easypoi.util.PoiValidationUtil; | import cn.afterturn.easypoi.util.PoiValidationUtil; | ||||
| @@ -41,7 +41,7 @@ public class CsvImportService extends ImportBaseService { | |||||
| this.cellValueServer = new CellValueService(); | this.cellValueServer = new CellValueService(); | ||||
| } | } | ||||
| public <T> List<T> readExcel(InputStream inputstream, Class<?> pojoClass, CsvImportParams params, ICsvSaveDataHandler saveDataHandler) { | |||||
| public <T> List<T> readExcel(InputStream inputstream, Class<?> pojoClass, CsvImportParams params, IReadHandler readHandler) { | |||||
| List collection = new ArrayList(); | List collection = new ArrayList(); | ||||
| try { | try { | ||||
| Map<String, ExcelImportEntity> excelParams = new HashMap<String, ExcelImportEntity>(); | Map<String, ExcelImportEntity> excelParams = new HashMap<String, ExcelImportEntity>(); | ||||
| @@ -120,8 +120,8 @@ public class CsvImportService extends ImportBaseService { | |||||
| addListContinue(object, param, row, titlemap, targetId, params, errorMsg); | addListContinue(object, param, row, titlemap, targetId, params, errorMsg); | ||||
| } | } | ||||
| if (verifyingDataValidity(object, params, pojoClass, errorMsg)) { | if (verifyingDataValidity(object, params, pojoClass, errorMsg)) { | ||||
| if (saveDataHandler != null) { | |||||
| saveDataHandler.save(object); | |||||
| if (readHandler != null) { | |||||
| readHandler.handler(object); | |||||
| } else { | } else { | ||||
| collection.add(object); | collection.add(object); | ||||
| } | } | ||||
| @@ -138,6 +138,9 @@ public class CsvImportService extends ImportBaseService { | |||||
| } | } | ||||
| readRow++; | readRow++; | ||||
| } | } | ||||
| if (readHandler != null) { | |||||
| readHandler.doAfterAll(); | |||||
| } | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| LOGGER.error(e.getMessage(), e); | LOGGER.error(e.getMessage(), e); | ||||
| } | } | ||||
| @@ -20,6 +20,7 @@ import java.io.FileInputStream; | |||||
| import java.io.InputStream; | import java.io.InputStream; | ||||
| import java.util.List; | import java.util.List; | ||||
| import cn.afterturn.easypoi.handler.inter.IReadHandler; | |||||
| import org.apache.poi.util.IOUtils; | import org.apache.poi.util.IOUtils; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| @@ -28,9 +29,7 @@ import cn.afterturn.easypoi.excel.entity.ImportParams; | |||||
| import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; | import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; | ||||
| import cn.afterturn.easypoi.excel.imports.ExcelImportService; | import cn.afterturn.easypoi.excel.imports.ExcelImportService; | ||||
| import cn.afterturn.easypoi.excel.imports.sax.SaxReadExcel; | import cn.afterturn.easypoi.excel.imports.sax.SaxReadExcel; | ||||
| import cn.afterturn.easypoi.excel.imports.sax.parse.ISaxRowRead; | |||||
| import cn.afterturn.easypoi.exception.excel.ExcelImportException; | import cn.afterturn.easypoi.exception.excel.ExcelImportException; | ||||
| import cn.afterturn.easypoi.handler.inter.IExcelReadRowHandler; | |||||
| /** | /** | ||||
| * Excel 导入工具 | * Excel 导入工具 | ||||
| @@ -124,20 +123,6 @@ public class ExcelImportUtil { | |||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * Excel 通过SAX解析方法,适合大数据导入,不支持图片 | |||||
| * 导入 数据源IO流,不返回校验结果 导入 字段类型 Integer,Long,Double,Date,String,Boolean | |||||
| * | |||||
| * @param inputstream | |||||
| * @param pojoClass | |||||
| * @param params | |||||
| * @return | |||||
| */ | |||||
| public static <T> List<T> importExcelBySax(InputStream inputstream, Class<?> pojoClass, | |||||
| ImportParams params) { | |||||
| return new SaxReadExcel().readExcel(inputstream, pojoClass, params, null, null); | |||||
| } | |||||
| /** | /** | ||||
| * Excel 通过SAX解析方法,适合大数据导入,不支持图片 | * Excel 通过SAX解析方法,适合大数据导入,不支持图片 | ||||
| * 导入 数据源本地文件,不返回校验结果 导入 字 段类型 Integer,Long,Double,Date,String,Boolean | * 导入 数据源本地文件,不返回校验结果 导入 字 段类型 Integer,Long,Double,Date,String,Boolean | ||||
| @@ -149,20 +134,8 @@ public class ExcelImportUtil { | |||||
| */ | */ | ||||
| @SuppressWarnings("rawtypes") | @SuppressWarnings("rawtypes") | ||||
| public static void importExcelBySax(InputStream inputstream, Class<?> pojoClass, | public static void importExcelBySax(InputStream inputstream, Class<?> pojoClass, | ||||
| ImportParams params, IExcelReadRowHandler hanlder) { | |||||
| new SaxReadExcel().readExcel(inputstream, pojoClass, params, null, hanlder); | |||||
| } | |||||
| /** | |||||
| * Excel 通过SAX解析方法,适合大数据导入,不支持图片 | |||||
| * 导入 数据源IO流,不返回校验结果 导入 字段类型 Integer,Long,Double,Date,String,Boolean | |||||
| * | |||||
| * @param inputstream | |||||
| * @param rowRead | |||||
| * @return | |||||
| */ | |||||
| public static <T> List<T> importExcelBySax(InputStream inputstream, ISaxRowRead rowRead) { | |||||
| return new SaxReadExcel().readExcel(inputstream, null, null, rowRead, null); | |||||
| ImportParams params, IReadHandler hanlder) { | |||||
| new SaxReadExcel().readExcel(inputstream, pojoClass, params, hanlder); | |||||
| } | } | ||||
| } | } | ||||
| @@ -19,6 +19,7 @@ import java.io.InputStream; | |||||
| import java.util.Iterator; | import java.util.Iterator; | ||||
| import java.util.List; | import java.util.List; | ||||
| import cn.afterturn.easypoi.handler.inter.IReadHandler; | |||||
| import org.apache.poi.openxml4j.opc.OPCPackage; | import org.apache.poi.openxml4j.opc.OPCPackage; | ||||
| import org.apache.poi.xssf.eventusermodel.XSSFReader; | import org.apache.poi.xssf.eventusermodel.XSSFReader; | ||||
| import org.apache.poi.xssf.model.SharedStringsTable; | import org.apache.poi.xssf.model.SharedStringsTable; | ||||
| @@ -34,7 +35,6 @@ import cn.afterturn.easypoi.excel.entity.ImportParams; | |||||
| import cn.afterturn.easypoi.excel.imports.sax.parse.ISaxRowRead; | import cn.afterturn.easypoi.excel.imports.sax.parse.ISaxRowRead; | ||||
| import cn.afterturn.easypoi.excel.imports.sax.parse.SaxRowRead; | import cn.afterturn.easypoi.excel.imports.sax.parse.SaxRowRead; | ||||
| import cn.afterturn.easypoi.exception.excel.ExcelImportException; | import cn.afterturn.easypoi.exception.excel.ExcelImportException; | ||||
| import cn.afterturn.easypoi.handler.inter.IExcelReadRowHandler; | |||||
| /** | /** | ||||
| * 基于SAX Excel大数据读取,读取Excel 07版本,不支持图片读取 | * 基于SAX Excel大数据读取,读取Excel 07版本,不支持图片读取 | ||||
| @@ -48,10 +48,10 @@ public class SaxReadExcel { | |||||
| private static final Logger LOGGER = LoggerFactory.getLogger(SaxReadExcel.class); | private static final Logger LOGGER = LoggerFactory.getLogger(SaxReadExcel.class); | ||||
| public <T> List<T> readExcel(InputStream inputstream, Class<?> pojoClass, ImportParams params, | public <T> List<T> readExcel(InputStream inputstream, Class<?> pojoClass, ImportParams params, | ||||
| ISaxRowRead rowRead, IExcelReadRowHandler hanlder) { | |||||
| IReadHandler hanlder) { | |||||
| try { | try { | ||||
| OPCPackage opcPackage = OPCPackage.open(inputstream); | OPCPackage opcPackage = OPCPackage.open(inputstream); | ||||
| return readExcel(opcPackage, pojoClass, params, rowRead, hanlder); | |||||
| return readExcel(opcPackage, pojoClass, params, null, hanlder); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| LOGGER.error(e.getMessage(), e); | LOGGER.error(e.getMessage(), e); | ||||
| throw new ExcelImportException(e.getMessage()); | throw new ExcelImportException(e.getMessage()); | ||||
| @@ -59,7 +59,7 @@ public class SaxReadExcel { | |||||
| } | } | ||||
| private <T> List<T> readExcel(OPCPackage opcPackage, Class<?> pojoClass, ImportParams params, | private <T> List<T> readExcel(OPCPackage opcPackage, Class<?> pojoClass, ImportParams params, | ||||
| ISaxRowRead rowRead, IExcelReadRowHandler hanlder) { | |||||
| ISaxRowRead rowRead, IReadHandler hanlder) { | |||||
| try { | try { | ||||
| XSSFReader xssfReader = new XSSFReader(opcPackage); | XSSFReader xssfReader = new XSSFReader(opcPackage); | ||||
| SharedStringsTable sst = xssfReader.getSharedStringsTable(); | SharedStringsTable sst = xssfReader.getSharedStringsTable(); | ||||
| @@ -22,6 +22,7 @@ import java.util.HashMap; | |||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Map; | import java.util.Map; | ||||
| import cn.afterturn.easypoi.handler.inter.IReadHandler; | |||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| @@ -36,7 +37,6 @@ import cn.afterturn.easypoi.excel.entity.sax.SaxReadCellEntity; | |||||
| import cn.afterturn.easypoi.excel.imports.CellValueService; | import cn.afterturn.easypoi.excel.imports.CellValueService; | ||||
| import cn.afterturn.easypoi.excel.imports.base.ImportBaseService; | import cn.afterturn.easypoi.excel.imports.base.ImportBaseService; | ||||
| import cn.afterturn.easypoi.exception.excel.ExcelImportException; | import cn.afterturn.easypoi.exception.excel.ExcelImportException; | ||||
| import cn.afterturn.easypoi.handler.inter.IExcelReadRowHandler; | |||||
| import cn.afterturn.easypoi.util.PoiPublicUtil; | import cn.afterturn.easypoi.util.PoiPublicUtil; | ||||
| import cn.afterturn.easypoi.util.PoiReflectorUtil; | import cn.afterturn.easypoi.util.PoiReflectorUtil; | ||||
| @@ -69,9 +69,9 @@ public class SaxRowRead extends ImportBaseService implements ISaxRowRead { | |||||
| private CellValueService cellValueServer; | private CellValueService cellValueServer; | ||||
| private IExcelReadRowHandler hanlder; | |||||
| private IReadHandler hanlder; | |||||
| public SaxRowRead(Class<?> pojoClass, ImportParams params, IExcelReadRowHandler hanlder) { | |||||
| public SaxRowRead(Class<?> pojoClass, ImportParams params, IReadHandler hanlder) { | |||||
| list = Lists.newArrayList(); | list = Lists.newArrayList(); | ||||
| this.params = params; | this.params = params; | ||||
| this.pojoClass = pojoClass; | this.pojoClass = pojoClass; | ||||
| @@ -21,11 +21,17 @@ package cn.afterturn.easypoi.handler.inter; | |||||
| * 2015年1月16日 下午8:06:26 | * 2015年1月16日 下午8:06:26 | ||||
| * @param <T> | * @param <T> | ||||
| */ | */ | ||||
| public interface IExcelReadRowHandler<T> { | |||||
| public interface IReadHandler<T> { | |||||
| /** | /** | ||||
| * 处理解析对象 | * 处理解析对象 | ||||
| * @param t | * @param t | ||||
| */ | */ | ||||
| public void handler(T t); | public void handler(T t); | ||||
| /** | |||||
| * 处理完成之后的业务 | |||||
| */ | |||||
| public void doAfterAll(); | |||||
| } | } | ||||
| @@ -4,7 +4,7 @@ | |||||
| <parent> | <parent> | ||||
| <groupId>cn.afterturn</groupId> | <groupId>cn.afterturn</groupId> | ||||
| <artifactId>easypoi</artifactId> | <artifactId>easypoi</artifactId> | ||||
| <version>4.0.0-SNAPSHOT</version> | |||||
| <version>4.0.0</version> | |||||
| </parent> | </parent> | ||||
| <artifactId>easypoi-web</artifactId> | <artifactId>easypoi-web</artifactId> | ||||
| <dependencies> | <dependencies> | ||||
| @@ -3,7 +3,7 @@ | |||||
| <modelVersion>4.0.0</modelVersion> | <modelVersion>4.0.0</modelVersion> | ||||
| <groupId>cn.afterturn</groupId> | <groupId>cn.afterturn</groupId> | ||||
| <artifactId>easypoi</artifactId> | <artifactId>easypoi</artifactId> | ||||
| <version>4.0.0-SNAPSHOT</version> | |||||
| <version>4.0.0</version> | |||||
| <packaging>pom</packaging> | <packaging>pom</packaging> | ||||
| <name>easypoi</name> | <name>easypoi</name> | ||||
| <modules> | <modules> | ||||
| @@ -45,7 +45,7 @@ | |||||
| </organization> | </organization> | ||||
| <properties> | <properties> | ||||
| <sub.version>4.0.0-SNAPSHOT</sub.version> | |||||
| <sub.version>4.0.0</sub.version> | |||||
| <poi.version>4.0.0</poi.version> | <poi.version>4.0.0</poi.version> | ||||
| <xerces.version>2.9.1</xerces.version> | <xerces.version>2.9.1</xerces.version> | ||||
| <guava.version>16.0.1</guava.version> | <guava.version>16.0.1</guava.version> | ||||