| @@ -21,7 +21,10 @@ Spring Boot 支持 https://gitee.com/lemur/easypoi-spring-boot-starter | |||
| **[https://opensource.afterturn.cn/doc/easypoi.html](http://opensource.afterturn.cn/doc/easypoi.html)** | |||
| 下一步计划 | |||
| - 国际化,翻译文档以及注释 | |||
| - pdf全部改为模板导出方式 | |||
| - word模板和excel功能同步 | |||
| [用户征集](https://gitee.com/lemur/easypoi/issues/IFDX7) | |||
| @@ -64,13 +67,46 @@ EasyPoi的主要特点 | |||
| 4.AbstractView 支持,web导出可以简单明了 | |||
| --------------------------- | |||
| EasyPoi的几个入口工具类 | |||
| 什么场景该用哪个方法 | |||
| --------------------------- | |||
| 1.ExcelExportUtil Excel导出( | |||
| 普通导出,模板导出) | |||
| 2.ExcelImportUtil Excel导入 | |||
| 3.WordExportUtil Word导出(只支持docx ,doc版本poi存在图片的bug,暂不支持) | |||
| - 导出 | |||
| 1.正规excel导出 (格式简单,数据量可以,5W以内吧) | |||
| 注解方式: ExcelExportUtil.exportExcel(ExportParams entity, Class<?> pojoClass,Collection<?> dataSet) | |||
| 2.不定多少列,但是格式依然简单数据库不大 | |||
| 自定义方式: ExcelExportUtil.exportExcel(ExportParams entity, List<ExcelExportEntity> entityList,Collection<?> dataSet) | |||
| 3.数据量大超过5W,还在100W以内 | |||
| 注解方式 ExcelExportUtil.exportBigExcel(ExportParams entity, Class<?> pojoClass,IExcelExportServer server, Object queryParams) | |||
| 自定义方式: ExcelExportUtil.exportBigExcel(ExportParams entity, List<ExcelExportEntity> excelParams,IExcelExportServer server, Object queryParams) | |||
| 4.样式复杂,数据量尽量别大 | |||
| 模板导出 ExcelExportUtil.exportExcel(TemplateExportParams params, Map<String, Object> map) | |||
| 5.一次导出多个风格不一致的sheet | |||
| 模板导出 ExcelExportUtil.exportExcel(Map<Integer, Map<String, Object>> map,TemplateExportParams params) | |||
| 6.一个模板但是要导出非常多份 | |||
| 模板导出 ExcelExportUtil.exportExcelClone(Map<Integer, List<Map<String, Object>>> map,TemplateExportParams params) | |||
| 7.模板无法满足你的自定义,试试html | |||
| 自己构造html,然后我给你转成excel ExcelXorHtmlUtil.htmlToExcel(String html, ExcelType type) | |||
| 8.数据量过百万级了.放弃excel吧,csv导出 | |||
| 注解方式: CsvExportUtil.exportCsv(CsvExportParams params, Class<?> pojoClass, OutputStream outputStream) | |||
| 自定义方式: CsvExportUtil.exportCsv(CsvExportParams params, List<ExcelExportEntity> entityList, OutputStream outputStream) | |||
| 9.word导出 | |||
| 模板导出: WordExportUtil.exportWord07(String url, Map<String, Object> map) | |||
| 10.PDF导出 | |||
| 模板导出: TODO | |||
| - 导入 | |||
| 如果想提高性能 ImportParams 的concurrentTask 可以帮助并发导入,仅单行,最小1000 | |||
| excel有单个的那种特殊读取,readSingleCell 参数可以支持 | |||
| 1. 不需要检验,数据量不大(5W以内) | |||
| 注解或者MAP: ExcelImportUtil.importExcel(File file, Class<?> pojoClass, ImportParams params) | |||
| 2. 需要导入,数据量不大 | |||
| 注解或者MAP: ExcelImportUtil.importExcelMore(InputStream inputstream, Class<?> pojoClass, ImportParams params) | |||
| 3. 数据量大了,或者你有特别多的导入操作,内存比较少,仅支持单行 | |||
| SAX方式 ExcelImportUtil.importExcelBySax(InputStream inputstream, Class<?> pojoClass, ImportParams params, IReadHandler handler) | |||
| 4. 数据量超过EXCEL限制,CSV读取 | |||
| 小数据量: CsvImportUtil.importCsv(InputStream inputstream, Class<?> pojoClass,CsvImportParams params) | |||
| 大数据量: CsvImportUtil.importCsv(InputStream inputstream, Class<?> pojoClass,CsvImportParams params, IReadHandler readHandler) | |||
| --------------------------- | |||
| 关于Excel导出XLS和XLSX区别 | |||
| @@ -96,24 +132,24 @@ SNAPSHOT 版本-很少发布 | |||
| https://oss.sonatype.org/content/groups/public/ | |||
| ```xml | |||
| <dependency> | |||
| <groupId>cn.afterturn</groupId> | |||
| <artifactId>easypoi-spring-boot-starter</artifactId> | |||
| <version>4.1.1</version> | |||
| </dependency> | |||
| <groupId>cn.afterturn</groupId> | |||
| <artifactId>easypoi-spring-boot-starter</artifactId> | |||
| <version>4.1.2</version> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>cn.afterturn</groupId> | |||
| <artifactId>easypoi-base</artifactId> | |||
| <version>4.1.1</version> | |||
| <version>4.1.2</version> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>cn.afterturn</groupId> | |||
| <artifactId>easypoi-web</artifactId> | |||
| <version>4.1.1</version> | |||
| <version>4.1.2</version> | |||
| </dependency> | |||
| <dependency> | |||
| <groupId>cn.afterturn</groupId> | |||
| <artifactId>easypoi-annotation</artifactId> | |||
| <version>4.1.1</version> | |||
| <version>4.1.2</version> | |||
| </dependency> | |||
| ``` | |||
| @@ -558,7 +558,8 @@ public class ExcelImportService extends ImportBaseService { | |||
| List<ExcelCollectionParams> excelCollection) { | |||
| if (params.getImportFields() != null) { | |||
| if (params.isNeedCheckOrder()) { // 同时校验列顺序 | |||
| // 同时校验列顺序 | |||
| if (params.isNeedCheckOrder()) { | |||
| if (params.getImportFields().length != titlemap.size()) { | |||
| LOGGER.error("excel列顺序不一致"); | |||
| @@ -48,18 +48,18 @@ public class SaxReadExcel { | |||
| private static final Logger LOGGER = LoggerFactory.getLogger(SaxReadExcel.class); | |||
| public <T> List<T> readExcel(InputStream inputstream, Class<?> pojoClass, ImportParams params, | |||
| IReadHandler hanlder) { | |||
| public void readExcel(InputStream inputstream, Class<?> pojoClass, ImportParams params, | |||
| IReadHandler handler) { | |||
| try { | |||
| OPCPackage opcPackage = OPCPackage.open(inputstream); | |||
| return readExcel(opcPackage, pojoClass, params, null, hanlder); | |||
| readExcel(opcPackage, pojoClass, params, null, handler); | |||
| } catch (Exception e) { | |||
| LOGGER.error(e.getMessage(), e); | |||
| throw new ExcelImportException(e.getMessage()); | |||
| } | |||
| } | |||
| private <T> List<T> readExcel(OPCPackage opcPackage, Class<?> pojoClass, ImportParams params, | |||
| private void readExcel(OPCPackage opcPackage, Class<?> pojoClass, ImportParams params, | |||
| ISaxRowRead rowRead, IReadHandler handler) { | |||
| try { | |||
| XSSFReader xssfReader = new XSSFReader(opcPackage); | |||
| @@ -81,12 +81,10 @@ public class SaxReadExcel { | |||
| sheet.close(); | |||
| } | |||
| sheetIndex++; | |||
| } | |||
| if (handler != null) { | |||
| handler.doAfterAll(); | |||
| } | |||
| return rowRead.getList(); | |||
| } catch (Exception e) { | |||
| LOGGER.error(e.getMessage(), e); | |||
| throw new ExcelImportException("SAX导入数据失败"); | |||
| @@ -19,19 +19,17 @@ import java.util.List; | |||
| import cn.afterturn.easypoi.excel.entity.sax.SaxReadCellEntity; | |||
| /** | |||
| * @author jueyue | |||
| * @since 3.1 | |||
| * @date 2017-11-9 13:04:06 | |||
| */ | |||
| public interface ISaxRowRead { | |||
| /** | |||
| * 获取返回数据 | |||
| * @param <T> | |||
| * @return | |||
| */ | |||
| public <T> List<T> getList(); | |||
| /** | |||
| * 解析数据 | |||
| * @param index | |||
| * @param datas | |||
| * @param cellList | |||
| */ | |||
| public void parse(int index, List<SaxReadCellEntity> datas); | |||
| void parse(int index, List<SaxReadCellEntity> cellList); | |||
| } | |||
| @@ -45,10 +45,6 @@ public class SaxRowRead extends ImportBaseService implements ISaxRowRead { | |||
| private static final Logger LOGGER = LoggerFactory | |||
| .getLogger(SaxRowRead.class); | |||
| /** | |||
| * 需要返回的数据 | |||
| **/ | |||
| private List list; | |||
| /** | |||
| * 导出的对象 | |||
| **/ | |||
| @@ -77,7 +73,6 @@ public class SaxRowRead extends ImportBaseService implements ISaxRowRead { | |||
| private IReadHandler handler; | |||
| public SaxRowRead(Class<?> pojoClass, ImportParams params, IReadHandler handler) { | |||
| list = Lists.newArrayList(); | |||
| this.params = params; | |||
| this.pojoClass = pojoClass; | |||
| cellValueServer = new CellValueService(); | |||
| @@ -102,25 +97,20 @@ public class SaxRowRead extends ImportBaseService implements ISaxRowRead { | |||
| } | |||
| @Override | |||
| public <T> List<T> getList() { | |||
| return list; | |||
| } | |||
| @Override | |||
| public void parse(int index, List<SaxReadCellEntity> datas) { | |||
| public void parse(int index, List<SaxReadCellEntity> cellList) { | |||
| try { | |||
| if (datas == null || datas.size() == 0) { | |||
| if (cellList == null || cellList.size() == 0) { | |||
| return; | |||
| } | |||
| //标题行跳过 | |||
| //skip title | |||
| if (index < params.getTitleRows()) { | |||
| return; | |||
| } | |||
| //表头行 | |||
| //skip head | |||
| if (index < params.getTitleRows() + params.getHeadRows()) { | |||
| addHeadData(datas); | |||
| addHeadData(cellList); | |||
| } else { | |||
| addListData(datas); | |||
| addListData(cellList); | |||
| } | |||
| } catch (Exception e) { | |||
| LOGGER.error(e.getMessage(), e); | |||
| @@ -161,9 +151,6 @@ public class SaxRowRead extends ImportBaseService implements ISaxRowRead { | |||
| for (ExcelCollectionParams param : excelCollection) { | |||
| addListContinue(object, param, datas, titlemap, targetId, params); | |||
| } | |||
| if (handler == null) { | |||
| list.add(object); | |||
| } | |||
| } | |||
| } | |||