├── easypoi-base ├── .gitignore ├── .settings │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.core.resources.prefs │ └── org.eclipse.jdt.core.prefs ├── src │ └── main │ │ └── java │ │ └── org │ │ └── jeecgframework │ │ └── poi │ │ ├── excel │ │ ├── imports │ │ │ ├── package-info.java │ │ │ ├── sax │ │ │ │ ├── parse │ │ │ │ │ └── ISaxRowRead.java │ │ │ │ ├── SaxReadExcel.java │ │ │ │ └── SheetHandler.java │ │ │ └── verifys │ │ │ │ ├── VerifyHandlerServer.java │ │ │ │ └── BaseVerifyHandler.java │ │ ├── entity │ │ │ ├── enmus │ │ │ │ ├── ExcelType.java │ │ │ │ ├── CellValueType.java │ │ │ │ └── ExcelStyleType.java │ │ │ ├── vo │ │ │ │ └── PoiBaseConstants.java │ │ │ ├── ExcelBaseParams.java │ │ │ ├── params │ │ │ │ ├── ExcelTemplateParams.java │ │ │ │ ├── ExcelCollectionParams.java │ │ │ │ ├── MergeEntity.java │ │ │ │ ├── ExcelBaseEntity.java │ │ │ │ ├── ExcelImportEntity.java │ │ │ │ ├── ExcelVerifyEntity.java │ │ │ │ └── ExcelExportEntity.java │ │ │ ├── result │ │ │ │ ├── ExcelVerifyHanlderResult.java │ │ │ │ └── ExcelImportResult.java │ │ │ ├── sax │ │ │ │ └── SaxReadCellEntity.java │ │ │ ├── ImportParams.java │ │ │ ├── TemplateExportParams.java │ │ │ └── ExportParams.java │ │ ├── html │ │ │ ├── helper │ │ │ │ ├── excelStyle.css │ │ │ │ ├── MergedRegionHelper.java │ │ │ │ └── CellValueHelper.java │ │ │ └── ExcelToHtmlServer.java │ │ ├── ExcelToHtmlUtil.java │ │ ├── export │ │ │ └── styler │ │ │ │ ├── IExcelExportStyler.java │ │ │ │ ├── AbstractExcelExportStyler.java │ │ │ │ ├── ExcelExportStylerDefaultImpl.java │ │ │ │ ├── ExcelExportStylerBorderImpl.java │ │ │ │ └── ExcelExportStylerColorImpl.java │ │ ├── ExcelExportUtil.java │ │ └── ExcelImportUtil.java │ │ ├── handler │ │ ├── package-info.java │ │ ├── impl │ │ │ ├── package-info.java │ │ │ └── ExcelDataHandlerDefaultImpl.java │ │ └── inter │ │ │ ├── IExcelReadRowHanlder.java │ │ │ ├── IExcelVerifyHandler.java │ │ │ └── IExcelDataHandler.java │ │ ├── cache │ │ ├── package-info.java │ │ ├── WordCache.java │ │ ├── manager │ │ │ ├── POICacheManager.java │ │ │ └── FileLoade.java │ │ └── ExcelCache.java │ │ ├── package-info.java │ │ ├── exception │ │ ├── excel │ │ │ ├── enums │ │ │ │ ├── ExcelImportEnum.java │ │ │ │ └── ExcelExportEnum.java │ │ │ ├── ExcelImportException.java │ │ │ └── ExcelExportException.java │ │ └── word │ │ │ ├── enmus │ │ │ └── WordExportEnum.java │ │ │ └── WordExportException.java │ │ ├── word │ │ ├── WordExportUtil.java │ │ ├── entity │ │ │ ├── params │ │ │ │ ├── ListParamEntity.java │ │ │ │ └── ExcelListEntity.java │ │ │ ├── WordImageEntity.java │ │ │ └── MyXWPFDocument.java │ │ └── parse │ │ │ └── excel │ │ │ └── ExcelMapParse.java │ │ └── util │ │ ├── PoiSheetUtility.java │ │ └── PoiFunctionUtil.java ├── .project ├── .classpath └── pom.xml ├── easypoi-web ├── .gitignore ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.m2e.core.prefs │ └── org.eclipse.jdt.core.prefs ├── .project ├── .classpath ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── jeecgframework │ └── poi │ └── excel │ ├── entity │ └── vo │ │ ├── BasePOIConstants.java │ │ ├── NormalExcelConstants.java │ │ ├── MapExcelConstants.java │ │ ├── TemplateWordConstants.java │ │ └── TemplateExcelConstants.java │ └── view │ ├── MiniAbstractExcelView.java │ ├── JeecgTemplateWordView.java │ ├── JeecgMapExcelView.java │ ├── JeecgTemplateExcelView.java │ └── JeecgSingleExcelView.java ├── install.bat ├── deploy.bat ├── .gitignore ├── .settings └── org.eclipse.m2e.core.prefs ├── easypoi-annotation ├── .settings │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.core.resources.prefs │ └── org.eclipse.jdt.core.prefs ├── pom.xml ├── .project ├── .classpath └── src │ └── main │ └── java │ └── org │ └── jeecgframework │ └── poi │ └── excel │ └── annotation │ ├── ExcelIgnore.java │ ├── ExcelTarget.java │ ├── ExcelEntity.java │ ├── ExcelCollection.java │ ├── ExcelVerify.java │ └── Excel.java └── .project /easypoi-base/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /easypoi-web/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /install.bat: -------------------------------------------------------------------------------- 1 | cmd /k mvn clean install -D skipTest -------------------------------------------------------------------------------- /deploy.bat: -------------------------------------------------------------------------------- 1 | cmd /k mvn clean deploy -Dmaven.test.skip=true -Dgpg.passphrase=jeecg123456 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Package Files # 4 | *.jar 5 | *.war 6 | *.ear 7 | target/ 8 | deploy.bat 9 | -------------------------------------------------------------------------------- /easypoi-web/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles=cc-mzone-profile 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /easypoi-base/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /easypoi-web/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /easypoi-annotation/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /easypoi-base/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/test/java=UTF-8 4 | -------------------------------------------------------------------------------- /easypoi-annotation/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/test/java=UTF-8 4 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/imports/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 导入类 3 | * @author JueYue 4 | * @date 2014年6月23日 下午11:05:59 5 | */ 6 | package org.jeecgframework.poi.excel.imports; -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/handler/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 数据处理中心,对导入导出进行数据处理 3 | * @author JueYue 4 | * @date 2014年6月20日 上午12:08:09 5 | */ 6 | package org.jeecgframework.poi.handler; -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/handler/impl/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 对接口的抽象的默认实现,避免用户实现过多方法 3 | * @author JueYue 4 | * @date 2014年6月20日 上午12:09:27 5 | */ 6 | package org.jeecgframework.poi.handler.impl; -------------------------------------------------------------------------------- /easypoi-base/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.6 6 | -------------------------------------------------------------------------------- /easypoi-web/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.6 6 | -------------------------------------------------------------------------------- /easypoi-annotation/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 5 | org.eclipse.jdt.core.compiler.source=1.6 6 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/cache/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 对POI用到的模板进行缓存,进行统一管理,缓存工具暂时使用guava(脱离配置文件) 3 | * 缓存方式统一为byte[] 屏蔽文件类型的差异 4 | * 缓存获取方式,URL或者URL+index(EXcel的) 5 | */ 6 | /** 7 | * @author JueYue 8 | * @date 2014年2月10日 9 | * @version 1.0 10 | */ 11 | package org.jeecgframework.poi.cache; -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author JueYue 3 | * @date 2014年2月10日 4 | * @version 1.0 5 | * 对POI进行封装,通过注解的使用,完成POI的简易重复操作 6 | * 通过模板完成较为复杂的操作 7 | * 进阶步骤:
8 | *

1.了解注解,图片类

9 | *

2.模板语言

10 | *

3.模板组合

11 | * 12 | */ 13 | package org.jeecgframework.poi; -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | easypoi 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /easypoi-annotation/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.jeecg 6 | easypoi 7 | 2.1.3 8 | 9 | easypoi-annotation 10 | 基础注解类,解耦合 11 | -------------------------------------------------------------------------------- /easypoi-base/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | easypoi-base 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /easypoi-annotation/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | easypoi-annotation 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /easypoi-web/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | easypoi-web 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.springframework.ide.eclipse.core.springbuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | 25 | org.springframework.ide.eclipse.core.springnature 26 | org.eclipse.jdt.core.javanature 27 | org.eclipse.m2e.core.maven2Nature 28 | 29 | 30 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/enmus/ExcelType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.entity.enmus; 17 | 18 | /** 19 | * Excel Type 20 | * @author JueYue 21 | * @date 2014年12月29日 下午9:08:21 22 | */ 23 | public enum ExcelType { 24 | 25 | HSSF, XSSF; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/enmus/CellValueType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.entity.enmus; 17 | 18 | /** 19 | * Cell 值得类型 20 | * @author JueYue 21 | * @date 2014年12月29日 下午10:20:49 22 | */ 23 | public enum CellValueType { 24 | 25 | String, Number, Boolean, Date, TElement, Null, None; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/handler/inter/IExcelReadRowHanlder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.handler.inter; 17 | 18 | /** 19 | * 接口自定义处理类 20 | * @author JueYue 21 | * @date 2015年1月16日 下午8:06:26 22 | * @param 23 | */ 24 | public interface IExcelReadRowHanlder { 25 | /** 26 | * 处理解析对象 27 | * @param t 28 | */ 29 | public void hanlder(T t); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /easypoi-base/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /easypoi-web/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/helper/excelStyle.css: -------------------------------------------------------------------------------- 1 | .excelDefaults { 2 | background-color: white; 3 | color: black; 4 | text-decoration: none; 5 | direction: ltr; 6 | text-transform: none; 7 | text-indent: 0; 8 | letter-spacing: 0; 9 | word-spacing: 0; 10 | white-space: normal; 11 | unicode-bidi: normal; 12 | vertical-align: 0; 13 | text-shadow: none; 14 | padding: 0; 15 | margin: 0; 16 | border-collapse: collapse; 17 | white-space: pre-wrap; 18 | word-wrap: break-word; 19 | word-break: break-all; 20 | } 21 | 22 | .excelDefaults td { 23 | padding: 1px 5px; 24 | border: 1px solid silver; 25 | border-color: #000000; 26 | text-align: center; 27 | vertical-align: middle; 28 | font-size: 12pt; 29 | } 30 | 31 | .excelDefaults .colHeader { 32 | background-color: silver; 33 | font-weight: bold; 34 | border: 1px solid black; 35 | text-align: center; 36 | padding: 1px 5px; 37 | } 38 | 39 | .excelDefaults .rowHeader { 40 | background-color: silver; 41 | font-weight: bold; 42 | border: 1px solid black; 43 | text-align: right; 44 | padding: 1px 5px; 45 | } -------------------------------------------------------------------------------- /easypoi-annotation/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /easypoi-web/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.jeecg 6 | easypoi 7 | 2.1.3 8 | 9 | easypoi-web 10 | 11 | 12 | 13 | org.springframework 14 | spring-web 15 | 16 | 17 | org.springframework 18 | spring-webmvc 19 | 20 | 21 | org.springframework 22 | spring-core 23 | 24 | 25 | 26 | javax.servlet 27 | servlet-api 28 | provided 29 | 30 | 31 | 32 | org.jeecg 33 | easypoi-base 34 | 35 | 36 | -------------------------------------------------------------------------------- /easypoi-annotation/src/main/java/org/jeecgframework/poi/excel/annotation/ExcelIgnore.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.annotation; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | /** 24 | * 标记为excel 创建实体忽略,放置死循环的造成 25 | * @author JueYue 26 | * @date 2013-9-24 27 | * @version 1.0 28 | */ 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(ElementType.FIELD) 31 | public @interface ExcelIgnore { 32 | 33 | } 34 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/org/jeecgframework/poi/excel/entity/vo/BasePOIConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.entity.vo; 17 | 18 | /** 19 | * 基础POI常量 20 | * @author JueYue 21 | * @date 2014年6月30日 下午9:23:37 22 | */ 23 | interface BasePOIConstants { 24 | 25 | /** 26 | * 注解对象 27 | */ 28 | public final static String CLASS = "entity"; 29 | /** 30 | *表格参数 31 | */ 32 | public final static String PARAMS = "params"; 33 | /** 34 | *下载文件名称 35 | */ 36 | public final static String FILE_NAME = "fileName"; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/imports/sax/parse/ISaxRowRead.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.imports.sax.parse; 17 | 18 | import java.util.List; 19 | 20 | import org.jeecgframework.poi.excel.entity.sax.SaxReadCellEntity; 21 | 22 | public interface ISaxRowRead { 23 | /** 24 | * 获取返回数据 25 | * @param 26 | * @return 27 | */ 28 | public List getList(); 29 | /** 30 | * 解析数据 31 | * @param index 32 | * @param datas 33 | */ 34 | public void parse(int index, List datas); 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /easypoi-annotation/src/main/java/org/jeecgframework/poi/excel/annotation/ExcelTarget.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.annotation; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | /** 24 | * excel 导出是用于标记id的 25 | * 26 | * @author JueYue 27 | * 28 | */ 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target({ ElementType.TYPE }) 31 | public @interface ExcelTarget { 32 | /** 33 | * 定义excel导出ID 来限定导出字段 34 | */ 35 | public String value(); 36 | } 37 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/exception/excel/enums/ExcelImportEnum.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.exception.excel.enums; 17 | 18 | /** 19 | * 导出异常类型枚举 20 | * @author JueYue 21 | * @date 2014年6月19日 下午10:59:51 22 | */ 23 | public enum ExcelImportEnum { 24 | 25 | GET_VALUE_ERROR("Excel 值获取失败"), VERIFY_ERROR("值校验失败"); 26 | 27 | private String msg; 28 | 29 | ExcelImportEnum(String msg) { 30 | this.msg = msg; 31 | } 32 | 33 | public String getMsg() { 34 | return msg; 35 | } 36 | 37 | public void setMsg(String msg) { 38 | this.msg = msg; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/org/jeecgframework/poi/excel/entity/vo/NormalExcelConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.entity.vo; 17 | 18 | /** 19 | * 正常导出Excel 20 | * @Author JueYue on 14-3-8. 21 | * 静态常量 22 | */ 23 | public interface NormalExcelConstants extends BasePOIConstants { 24 | /** 25 | * 单Sheet导出 26 | */ 27 | public final static String JEECG_EXCEL_VIEW = "jeecgExcelView"; 28 | /** 29 | * 数据列表 30 | */ 31 | public final static String DATA_LIST = "data"; 32 | /** 33 | * 多Sheet 对象 34 | */ 35 | public final static String MAP_LIST = "mapList"; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/exception/excel/enums/ExcelExportEnum.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.exception.excel.enums; 17 | 18 | /** 19 | * 导出异常类型枚举 20 | * @author JueYue 21 | * @date 2014年6月19日 下午10:59:51 22 | */ 23 | public enum ExcelExportEnum { 24 | 25 | PARAMETER_ERROR("Excel 导出 参数错误"), EXPORT_ERROR("Excel导出错误"); 26 | 27 | private String msg; 28 | 29 | ExcelExportEnum(String msg) { 30 | this.msg = msg; 31 | } 32 | 33 | public String getMsg() { 34 | return msg; 35 | } 36 | 37 | public void setMsg(String msg) { 38 | this.msg = msg; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/org/jeecgframework/poi/excel/entity/vo/MapExcelConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.entity.vo; 17 | 18 | /** 19 | * 正常导出Excel 20 | * @Author JueYue on 14-3-8. 21 | * 静态常量 22 | */ 23 | public interface MapExcelConstants extends BasePOIConstants { 24 | /** 25 | * 单Sheet导出 26 | */ 27 | public final static String JEECG_MAP_EXCEL_VIEW = "jeecgMapExcelView"; 28 | /** 29 | * Entity List 30 | */ 31 | public final static String ENTITY_LIST = "data"; 32 | /** 33 | * 数据列表 34 | */ 35 | public final static String MAP_LIST = "mapList"; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/vo/PoiBaseConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.entity.vo; 17 | 18 | /** 19 | * 基础常量 20 | * Created by jue on 14-4-21. 21 | */ 22 | public interface PoiBaseConstants { 23 | /** 24 | * 字段属性对应方法 25 | */ 26 | public static String GET = "get"; 27 | /** 28 | * 字段属性对应方法 29 | */ 30 | public static String SET = "set"; 31 | /** 32 | * 字段属性对应方法 33 | */ 34 | public static String IS = "is"; 35 | /** 36 | * 是否增加属性列 37 | */ 38 | public static String IS_ADD_INDEX = "isAddIndex"; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/org/jeecgframework/poi/excel/entity/vo/TemplateWordConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.entity.vo; 17 | 18 | /** 19 | * Word 导出模板常量 20 | * @author JueYue 21 | * @date 2014年7月24日 下午11:26:46 22 | */ 23 | public interface TemplateWordConstants extends BasePOIConstants { 24 | /** 25 | * 模板导出 26 | */ 27 | public final static String JEECG_TEMPLATE_WORD_VIEW = "jeecgTemplateWordView"; 28 | /** 29 | * 数据列表 30 | */ 31 | public final static String URL = "url"; 32 | /** 33 | * 模板参数 34 | */ 35 | public final static String MAP_DATA = "map"; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/org/jeecgframework/poi/excel/entity/vo/TemplateExcelConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.entity.vo; 17 | 18 | /** 19 | * 模板Excel导出常量 20 | * @author JueYue 21 | * @date 2014年6月30日 下午9:26:52 22 | */ 23 | public interface TemplateExcelConstants extends BasePOIConstants { 24 | /** 25 | * 模板导出 26 | */ 27 | public final static String JEECG_TEMPLATE_EXCEL_VIEW = "jeecgTemplateExcelView"; 28 | /** 29 | * 数据列表 30 | */ 31 | public final static String LIST_DATA = "list"; 32 | /** 33 | * 模板参数 34 | */ 35 | public final static String MAP_DATA = "map"; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/ExcelBaseParams.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.entity; 17 | 18 | import org.jeecgframework.poi.handler.inter.IExcelDataHandler; 19 | 20 | /** 21 | * 基础参数 22 | * @author JueYue 23 | * @date 2014年6月20日 下午1:56:52 24 | */ 25 | public class ExcelBaseParams { 26 | 27 | /** 28 | * 数据处理接口,以此为主,replace,format都在这后面 29 | */ 30 | private IExcelDataHandler dataHanlder; 31 | 32 | public IExcelDataHandler getDataHanlder() { 33 | return dataHanlder; 34 | } 35 | 36 | public void setDataHanlder(IExcelDataHandler dataHanlder) { 37 | this.dataHanlder = dataHanlder; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/exception/word/enmus/WordExportEnum.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.exception.word.enmus; 17 | 18 | /** 19 | * 导出异常枚举 20 | * 21 | * @author JueYue 22 | * @date 2014年8月9日 下午10:34:58 23 | */ 24 | public enum WordExportEnum { 25 | 26 | EXCEL_PARAMS_ERROR ("Excel 导出 参数错误") , 27 | EXCEL_HEAD_HAVA_NULL ("Excel 表头 有的字段为空") , 28 | EXCEL_NO_HEAD ("Excel 没有表头"); 29 | 30 | private String msg; 31 | 32 | WordExportEnum(String msg) { 33 | this.msg = msg; 34 | } 35 | 36 | public String getMsg() { 37 | return msg; 38 | } 39 | 40 | public void setMsg(String msg) { 41 | this.msg = msg; 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/exception/word/WordExportException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.exception.word; 17 | 18 | import org.jeecgframework.poi.exception.word.enmus.WordExportEnum; 19 | 20 | /** 21 | * word导出异常 22 | * 23 | * @author JueYue 24 | * @date 2014年8月9日 下午10:32:51 25 | */ 26 | public class WordExportException extends RuntimeException { 27 | 28 | private static final long serialVersionUID = 1L; 29 | 30 | public WordExportException() { 31 | super(); 32 | } 33 | 34 | public WordExportException(String msg) { 35 | super(msg); 36 | } 37 | 38 | public WordExportException(WordExportEnum exception) { 39 | super(exception.getMsg()); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /easypoi-annotation/src/main/java/org/jeecgframework/poi/excel/annotation/ExcelEntity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.annotation; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | /** 24 | * 标记是不是导出excel 标记为实体类 25 | * 26 | * @author JueYue 27 | * 28 | */ 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(ElementType.FIELD) 31 | public @interface ExcelEntity { 32 | 33 | /** 34 | * 定义excel导出ID 来限定导出字段,处理一个类对应多个不同名称的情况 35 | */ 36 | public String id() default ""; 37 | 38 | /** 39 | * 导出时,对应数据库的字段 主要是用户区分每个字段, 不能有annocation重名的 导出时的列名 40 | * 导出排序跟定义了annotation的字段的顺序有关 可以使用a_id,b_id来确实是否使用 41 | */ 42 | public String name() default ""; 43 | } 44 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/ExcelToHtmlUtil.java: -------------------------------------------------------------------------------- 1 | package org.jeecgframework.poi.excel; 2 | 3 | import org.apache.poi.ss.usermodel.Workbook; 4 | import org.jeecgframework.poi.excel.html.ExcelToHtmlServer; 5 | 6 | /** 7 | * Excel 变成界面 8 | * @author JueYue 9 | * @date 2015年5月10日 上午11:51:48 10 | */ 11 | public final class ExcelToHtmlUtil { 12 | 13 | private ExcelToHtmlUtil() { 14 | } 15 | 16 | /** 17 | * 转换成为Table 18 | * @param wb Excel 19 | * @return 20 | */ 21 | public static String toTableHtml(Workbook wb) { 22 | return new ExcelToHtmlServer(wb, false, 0).printPage(); 23 | } 24 | 25 | /** 26 | * 转换成为Table 27 | * @param wb Excel 28 | * @param sheetNum sheetNum 29 | * @return 30 | */ 31 | public static String toTableHtml(Workbook wb, int sheetNum) { 32 | return new ExcelToHtmlServer(wb, false, sheetNum).printPage(); 33 | } 34 | 35 | /** 36 | * 转换成为完整界面 37 | * @param wb Excel 38 | * @param sheetNum sheetNum 39 | * @return 40 | */ 41 | public static String toAllHtml(Workbook wb) { 42 | return new ExcelToHtmlServer(wb, true, 0).printPage(); 43 | } 44 | 45 | /** 46 | * 转换成为完整界面 47 | * @param wb Excel 48 | * @param sheetNum sheetNum 49 | * @return 50 | */ 51 | public static String toAllHtml(Workbook wb, int sheetNum) { 52 | return new ExcelToHtmlServer(wb, true, sheetNum).printPage(); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/params/ExcelTemplateParams.java: -------------------------------------------------------------------------------- 1 | package org.jeecgframework.poi.excel.entity.params; 2 | 3 | import java.io.Serializable; 4 | 5 | import org.apache.poi.ss.usermodel.CellStyle; 6 | 7 | /** 8 | * 模板便利是的参数 9 | * @author JueYue 10 | * @date 2015年4月29日 下午9:22:48 11 | */ 12 | public class ExcelTemplateParams implements Serializable { 13 | 14 | /** 15 | * 16 | */ 17 | private static final long serialVersionUID = 1L; 18 | /** 19 | * key 20 | */ 21 | private String name; 22 | /** 23 | * 模板的cellStyle 24 | */ 25 | private CellStyle cellStyle; 26 | /** 27 | * 行高 28 | */ 29 | private short height; 30 | 31 | public ExcelTemplateParams() { 32 | 33 | } 34 | 35 | public ExcelTemplateParams(String name, CellStyle cellStyle, short height) { 36 | this.name = name; 37 | this.cellStyle = cellStyle; 38 | this.height = height; 39 | } 40 | 41 | public String getName() { 42 | return name; 43 | } 44 | 45 | public void setName(String name) { 46 | this.name = name; 47 | } 48 | 49 | public CellStyle getCellStyle() { 50 | return cellStyle; 51 | } 52 | 53 | public void setCellStyle(CellStyle cellStyle) { 54 | this.cellStyle = cellStyle; 55 | } 56 | 57 | public short getHeight() { 58 | return height; 59 | } 60 | 61 | public void setHeight(short height) { 62 | this.height = height; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/styler/IExcelExportStyler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.export.styler; 17 | 18 | import org.apache.poi.ss.usermodel.CellStyle; 19 | import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; 20 | 21 | /** 22 | * Excel导出样式接口 23 | * @author JueYue 24 | * @date 2015年1月9日 下午5:32:30 25 | */ 26 | public interface IExcelExportStyler { 27 | 28 | /** 29 | * 列表头样式 30 | * @param headerColor 31 | * @return 32 | */ 33 | public CellStyle getHeaderStyle(short headerColor); 34 | 35 | /** 36 | * 标题样式 37 | * @param color 38 | * @return 39 | */ 40 | public CellStyle getTitleStyle(short color); 41 | 42 | /** 43 | * 获取样式方法 44 | * @param noneStyler 45 | * @param entity 46 | * @return 47 | */ 48 | public CellStyle getStyles(boolean noneStyler, ExcelExportEntity entity); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/org/jeecgframework/poi/excel/view/MiniAbstractExcelView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.view; 17 | 18 | import javax.servlet.http.HttpServletRequest; 19 | 20 | import org.springframework.web.servlet.view.AbstractView; 21 | 22 | /** 23 | * 基础抽象Excel View 24 | * @author JueYue 25 | * @date 2015年2月28日 下午1:41:05 26 | */ 27 | public abstract class MiniAbstractExcelView extends AbstractView { 28 | 29 | private static final String CONTENT_TYPE = "application/vnd.ms-excel"; 30 | 31 | protected static final String HSSF = ".xls"; 32 | protected static final String XSSF = ".xlsx"; 33 | 34 | public MiniAbstractExcelView() { 35 | setContentType(CONTENT_TYPE); 36 | } 37 | 38 | protected boolean isIE(HttpServletRequest request) { 39 | return (request.getHeader("USER-AGENT").toLowerCase().indexOf("msie") > 0 || request 40 | .getHeader("USER-AGENT").toLowerCase().indexOf("rv:11.0") > 0) ? true : false; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/handler/inter/IExcelVerifyHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.handler.inter; 17 | 18 | import org.jeecgframework.poi.excel.entity.result.ExcelVerifyHanlderResult; 19 | 20 | /** 21 | * 导入校验接口 22 | * 23 | * @author JueYue 24 | * @date 2014年6月23日 下午11:08:21 25 | */ 26 | public interface IExcelVerifyHandler { 27 | 28 | /** 29 | * 获取需要处理的字段,导入和导出统一处理了, 减少书写的字段 30 | * 31 | * @return 32 | */ 33 | public String[] getNeedVerifyFields(); 34 | 35 | /** 36 | * 获取需要处理的字段,导入和导出统一处理了, 减少书写的字段 37 | * 38 | * @return 39 | */ 40 | public void setNeedVerifyFields(String[] arr); 41 | 42 | /** 43 | * 导出处理方法 44 | * 45 | * @param obj 46 | * 当前对象 47 | * @param name 48 | * 当前字段名称 49 | * @param value 50 | * 当前值 51 | * @return 52 | */ 53 | public ExcelVerifyHanlderResult verifyHandler(Object obj, String name, Object value); 54 | 55 | } 56 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/enmus/ExcelStyleType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.entity.enmus; 17 | 18 | import org.jeecgframework.poi.excel.export.styler.ExcelExportStylerBorderImpl; 19 | import org.jeecgframework.poi.excel.export.styler.ExcelExportStylerColorImpl; 20 | import org.jeecgframework.poi.excel.export.styler.ExcelExportStylerDefaultImpl; 21 | 22 | /** 23 | * 插件提供的几个默认样式 24 | * @author JueYue 25 | * @date 2015年1月9日 下午9:02:24 26 | */ 27 | public enum ExcelStyleType { 28 | 29 | NONE("默认样式", ExcelExportStylerDefaultImpl.class), 30 | BORDER("边框样式", ExcelExportStylerBorderImpl.class), 31 | COLOR("间隔行样式", ExcelExportStylerColorImpl.class); 32 | 33 | private String name; 34 | private Class clazz; 35 | 36 | ExcelStyleType(String name, Class clazz) { 37 | this.name = name; 38 | this.clazz = clazz; 39 | } 40 | 41 | public Class getClazz() { 42 | return clazz; 43 | } 44 | 45 | public String getName() { 46 | return name; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /easypoi-annotation/src/main/java/org/jeecgframework/poi/excel/annotation/ExcelCollection.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.annotation; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | import java.util.ArrayList; 23 | 24 | /** 25 | * 导出的集合 26 | * 27 | * @author JueYue 2013年8月24日 28 | */ 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(ElementType.FIELD) 31 | public @interface ExcelCollection { 32 | 33 | /** 34 | * 定义excel导出ID 来限定导出字段,处理一个类对应多个不同名称的情况 35 | */ 36 | public String id() default ""; 37 | 38 | /** 39 | * 导出时,对应数据库的字段 主要是用户区分每个字段, 不能有annocation重名的 导出时的列名 40 | * 导出排序跟定义了annotation的字段的顺序有关 可以使用a_id,b_id来确实是否使用 41 | */ 42 | public String name(); 43 | 44 | /** 45 | * 展示到第几个同样可以使用a_id,b_id 46 | * 47 | */ 48 | public String orderNum() default "0"; 49 | 50 | /** 51 | * 创建时创建的类型 默认值是 arrayList 52 | */ 53 | public Class type() default ArrayList.class; 54 | } 55 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/result/ExcelVerifyHanlderResult.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.entity.result; 17 | 18 | /** 19 | * Excel导入处理返回结果 20 | * 21 | * @author JueYue 22 | * @date 2014年6月23日 下午11:03:29 23 | */ 24 | public class ExcelVerifyHanlderResult { 25 | /** 26 | * 是否正确 27 | */ 28 | private boolean success; 29 | /** 30 | * 错误信息 31 | */ 32 | private String msg; 33 | 34 | public ExcelVerifyHanlderResult() { 35 | 36 | } 37 | 38 | public ExcelVerifyHanlderResult(boolean success) { 39 | this.success = success; 40 | } 41 | 42 | public ExcelVerifyHanlderResult(boolean success, String msg) { 43 | this.success = success; 44 | this.msg = msg; 45 | } 46 | 47 | public String getMsg() { 48 | return msg; 49 | } 50 | 51 | public boolean isSuccess() { 52 | return success; 53 | } 54 | 55 | public void setMsg(String msg) { 56 | this.msg = msg; 57 | } 58 | 59 | public void setSuccess(boolean success) { 60 | this.success = success; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/cache/WordCache.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.cache; 17 | 18 | import java.io.InputStream; 19 | 20 | import org.jeecgframework.poi.cache.manager.POICacheManager; 21 | import org.jeecgframework.poi.word.entity.MyXWPFDocument; 22 | import org.slf4j.Logger; 23 | import org.slf4j.LoggerFactory; 24 | 25 | /** 26 | * word 缓存中心 27 | * 28 | * @author JueYue 29 | * @date 2014年7月24日 下午10:54:31 30 | */ 31 | public class WordCache { 32 | 33 | private static final Logger LOGGER = LoggerFactory.getLogger(WordCache.class); 34 | 35 | public static MyXWPFDocument getXWPFDocumen(String url) { 36 | InputStream is = null; 37 | try { 38 | is = POICacheManager.getFile(url); 39 | MyXWPFDocument doc = new MyXWPFDocument(is); 40 | return doc; 41 | } catch (Exception e) { 42 | LOGGER.error(e.getMessage(),e); 43 | } finally { 44 | try { 45 | is.close(); 46 | } catch (Exception e) { 47 | LOGGER.error(e.getMessage(),e); 48 | } 49 | } 50 | return null; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/sax/SaxReadCellEntity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.entity.sax; 17 | 18 | import org.jeecgframework.poi.excel.entity.enmus.CellValueType; 19 | 20 | /** 21 | * Cell 对象 22 | * @author JueYue 23 | * @date 2014年12月29日 下午10:12:57 24 | */ 25 | public class SaxReadCellEntity { 26 | /** 27 | * 值类型 28 | */ 29 | private CellValueType cellType; 30 | /** 31 | * 值 32 | */ 33 | private Object value; 34 | 35 | public SaxReadCellEntity(CellValueType cellType, Object value) { 36 | this.cellType = cellType; 37 | this.value = value; 38 | } 39 | 40 | public CellValueType getCellType() { 41 | return cellType; 42 | } 43 | 44 | public void setCellType(CellValueType cellType) { 45 | this.cellType = cellType; 46 | } 47 | 48 | public Object getValue() { 49 | return value; 50 | } 51 | 52 | public void setValue(Object value) { 53 | this.value = value; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return "[type=" + cellType.toString() + ",value=" + value + "]"; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/handler/impl/ExcelDataHandlerDefaultImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.handler.impl; 17 | 18 | import java.util.Map; 19 | 20 | import org.jeecgframework.poi.handler.inter.IExcelDataHandler; 21 | 22 | /** 23 | * 数据处理默认实现,返回空 24 | * 25 | * @author JueYue 26 | * @date 2014年6月20日 上午12:11:52 27 | */ 28 | public abstract class ExcelDataHandlerDefaultImpl implements IExcelDataHandler { 29 | /** 30 | * 需要处理的字段 31 | */ 32 | private String[] needHandlerFields; 33 | 34 | @Override 35 | public Object exportHandler(Object obj, String name, Object value) { 36 | return value; 37 | } 38 | 39 | @Override 40 | public String[] getNeedHandlerFields() { 41 | return needHandlerFields; 42 | } 43 | 44 | @Override 45 | public Object importHandler(Object obj, String name, Object value) { 46 | return value; 47 | } 48 | 49 | @Override 50 | public void setNeedHandlerFields(String[] needHandlerFields) { 51 | this.needHandlerFields = needHandlerFields; 52 | } 53 | 54 | @Override 55 | public void setMapValue(Map map, String originKey, Object value) { 56 | map.put(originKey, value); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/exception/excel/ExcelImportException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.exception.excel; 17 | 18 | import org.jeecgframework.poi.exception.excel.enums.ExcelImportEnum; 19 | 20 | /** 21 | * 导入异常 22 | * @author JueYue 23 | * @date 2014年6月29日 下午2:23:43 24 | */ 25 | public class ExcelImportException extends RuntimeException { 26 | 27 | private static final long serialVersionUID = 1L; 28 | 29 | private ExcelImportEnum type; 30 | 31 | public ExcelImportException() { 32 | super(); 33 | } 34 | 35 | public ExcelImportException(ExcelImportEnum type) { 36 | super(type.getMsg()); 37 | this.type = type; 38 | } 39 | 40 | public ExcelImportException(ExcelImportEnum type, Throwable cause) { 41 | super(type.getMsg(), cause); 42 | } 43 | 44 | public ExcelImportException(String message) { 45 | super(message); 46 | } 47 | 48 | public ExcelImportException(String message, ExcelImportEnum type) { 49 | super(message); 50 | this.type = type; 51 | } 52 | 53 | public ExcelImportEnum getType() { 54 | return type; 55 | } 56 | 57 | public void setType(ExcelImportEnum type) { 58 | this.type = type; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/exception/excel/ExcelExportException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.exception.excel; 17 | 18 | import org.jeecgframework.poi.exception.excel.enums.ExcelExportEnum; 19 | 20 | /** 21 | * 导出异常 22 | * 23 | * @author JueYue 24 | * @date 2014年6月19日 下午10:56:18 25 | */ 26 | public class ExcelExportException extends RuntimeException { 27 | 28 | private static final long serialVersionUID = 1L; 29 | 30 | private ExcelExportEnum type; 31 | 32 | public ExcelExportException() { 33 | super(); 34 | } 35 | 36 | public ExcelExportException(ExcelExportEnum type) { 37 | super(type.getMsg()); 38 | this.type = type; 39 | } 40 | 41 | public ExcelExportException(ExcelExportEnum type, Throwable cause) { 42 | super(type.getMsg(), cause); 43 | } 44 | 45 | public ExcelExportException(String message) { 46 | super(message); 47 | } 48 | 49 | public ExcelExportException(String message, ExcelExportEnum type) { 50 | super(message); 51 | this.type = type; 52 | } 53 | 54 | public ExcelExportEnum getType() { 55 | return type; 56 | } 57 | 58 | public void setType(ExcelExportEnum type) { 59 | this.type = type; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/word/WordExportUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.word; 17 | 18 | import java.util.Map; 19 | 20 | import org.apache.poi.xwpf.usermodel.XWPFDocument; 21 | import org.jeecgframework.poi.word.parse.ParseWord07; 22 | 23 | /** 24 | * Word使用模板导出工具类 25 | * 26 | * @author JueYue 27 | * @date 2013-11-16 28 | * @version 1.0 29 | */ 30 | public final class WordExportUtil { 31 | 32 | private WordExportUtil() { 33 | 34 | } 35 | 36 | /** 37 | * 解析Word2007版本 38 | * 39 | * @param url 40 | * 模板地址 41 | * @param map 42 | * 解析数据源 43 | * @return 44 | */ 45 | public static XWPFDocument exportWord07(String url, Map map) throws Exception { 46 | return new ParseWord07().parseWord(url, map); 47 | } 48 | 49 | /** 50 | * 解析Word2007版本 51 | * 52 | * @param XWPFDocument 53 | * 模板 54 | * @param map 55 | * 解析数据源 56 | * @return 57 | */ 58 | public static void exportWord07(XWPFDocument document, Map map) 59 | throws Exception { 60 | new ParseWord07().parseWord(document, map); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /easypoi-base/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.jeecg 6 | easypoi 7 | 2.1.3 8 | 9 | easypoi-base 10 | 11 | 12 | 13 | org.apache.poi 14 | poi 15 | 16 | 17 | org.apache.poi 18 | poi-ooxml 19 | 20 | 21 | org.apache.poi 22 | poi-ooxml-schemas 23 | 24 | 25 | xerces 26 | xercesImpl 27 | 28 | 29 | 30 | 31 | 32 | xerces 33 | xercesImpl 34 | true 35 | 36 | 37 | 38 | org.apache.poi 39 | poi-scratchpad 40 | true 41 | 42 | 43 | 44 | 45 | com.google.guava 46 | guava 47 | 48 | 49 | 50 | org.apache.commons 51 | commons-lang3 52 | 53 | 54 | 55 | 56 | 57 | org.slf4j 58 | slf4j-api 59 | 60 | 61 | 62 | org.jeecg 63 | easypoi-annotation 64 | 65 | 66 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/result/ExcelImportResult.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.entity.result; 17 | 18 | import java.util.List; 19 | 20 | import org.apache.poi.ss.usermodel.Workbook; 21 | 22 | /** 23 | * 导入返回类 24 | * 25 | * @author JueYue 26 | * @date 2014年6月29日 下午5:12:10 27 | */ 28 | public class ExcelImportResult { 29 | 30 | /** 31 | * 结果集 32 | */ 33 | private List list; 34 | 35 | /** 36 | * 是否存在校验失败 37 | */ 38 | private boolean verfiyFail; 39 | 40 | /** 41 | * 数据源 42 | */ 43 | private Workbook workbook; 44 | 45 | public ExcelImportResult() { 46 | 47 | } 48 | 49 | public ExcelImportResult(List list, boolean verfiyFail, Workbook workbook) { 50 | this.list = list; 51 | this.verfiyFail = verfiyFail; 52 | this.workbook = workbook; 53 | } 54 | 55 | public List getList() { 56 | return list; 57 | } 58 | 59 | public Workbook getWorkbook() { 60 | return workbook; 61 | } 62 | 63 | public boolean isVerfiyFail() { 64 | return verfiyFail; 65 | } 66 | 67 | public void setList(List list) { 68 | this.list = list; 69 | } 70 | 71 | public void setVerfiyFail(boolean verfiyFail) { 72 | this.verfiyFail = verfiyFail; 73 | } 74 | 75 | public void setWorkbook(Workbook workbook) { 76 | this.workbook = workbook; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/handler/inter/IExcelDataHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.handler.inter; 17 | 18 | import java.util.Map; 19 | 20 | /** 21 | * Excel 导入导出 数据处理接口 22 | * 23 | * @author JueYue 24 | * @date 2014年6月19日 下午11:59:45 25 | */ 26 | public interface IExcelDataHandler { 27 | 28 | /** 29 | * 导出处理方法 30 | * 31 | * @param obj 32 | * 当前对象 33 | * @param name 34 | * 当前字段名称 35 | * @param value 36 | * 当前值 37 | * @return 38 | */ 39 | public Object exportHandler(Object obj, String name, Object value); 40 | 41 | /** 42 | * 获取需要处理的字段,导入和导出统一处理了, 减少书写的字段 43 | * 44 | * @return 45 | */ 46 | public String[] getNeedHandlerFields(); 47 | 48 | /** 49 | * 导入处理方法 当前对象,当前字段名称,当前值 50 | * 51 | * @param obj 52 | * 当前对象 53 | * @param name 54 | * 当前字段名称 55 | * @param value 56 | * 当前值 57 | * @return 58 | */ 59 | public Object importHandler(Object obj, String name, Object value); 60 | 61 | /** 62 | * 设置需要处理的属性列表 63 | * @param fields 64 | */ 65 | public void setNeedHandlerFields(String[] fields); 66 | 67 | /** 68 | * 设置Map导入,自定义 put 69 | * @param map 70 | * @param originKey 71 | * @param value 72 | */ 73 | public void setMapValue(Map map, String originKey, Object value); 74 | 75 | } 76 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/params/ExcelCollectionParams.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.entity.params; 17 | 18 | import java.util.Map; 19 | 20 | /** 21 | * Excel 对于的 Collection 22 | * 23 | * @author JueYue 24 | * @date 2013-9-26 25 | * @version 1.0 26 | */ 27 | public class ExcelCollectionParams { 28 | 29 | /** 30 | * 集合对应的名称 31 | */ 32 | private String name; 33 | /** 34 | * Excel 列名称 35 | */ 36 | private String excelName; 37 | /** 38 | * 实体对象 39 | */ 40 | private Class type; 41 | /** 42 | * 这个list下面的参数集合实体对象 43 | */ 44 | private Map excelParams; 45 | 46 | public Map getExcelParams() { 47 | return excelParams; 48 | } 49 | 50 | public String getName() { 51 | return name; 52 | } 53 | 54 | public Class getType() { 55 | return type; 56 | } 57 | 58 | public void setExcelParams(Map excelParams) { 59 | this.excelParams = excelParams; 60 | } 61 | 62 | public void setName(String name) { 63 | this.name = name; 64 | } 65 | 66 | public void setType(Class type) { 67 | this.type = type; 68 | } 69 | 70 | public String getExcelName() { 71 | return excelName; 72 | } 73 | 74 | public void setExcelName(String excelName) { 75 | this.excelName = excelName; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/params/MergeEntity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.entity.params; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * 合并单元格使用对象 22 | * 23 | * Created by jue on 14-6-11. 24 | */ 25 | public class MergeEntity { 26 | /** 27 | * 合并开始行 28 | */ 29 | private int startRow; 30 | /** 31 | * 合并结束行 32 | */ 33 | private int endRow; 34 | /** 35 | * 文字 36 | */ 37 | private String text; 38 | /** 39 | * 依赖关系文本 40 | */ 41 | private List relyList; 42 | 43 | public MergeEntity() { 44 | 45 | } 46 | 47 | public MergeEntity(String text, int startRow, int endRow) { 48 | this.text = text; 49 | this.endRow = endRow; 50 | this.startRow = startRow; 51 | } 52 | 53 | public int getEndRow() { 54 | return endRow; 55 | } 56 | 57 | public List getRelyList() { 58 | return relyList; 59 | } 60 | 61 | public int getStartRow() { 62 | return startRow; 63 | } 64 | 65 | public String getText() { 66 | return text; 67 | } 68 | 69 | public void setEndRow(int endRow) { 70 | this.endRow = endRow; 71 | } 72 | 73 | public void setRelyList(List relyList) { 74 | this.relyList = relyList; 75 | } 76 | 77 | public void setStartRow(int startRow) { 78 | this.startRow = startRow; 79 | } 80 | 81 | public void setText(String text) { 82 | this.text = text; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /easypoi-annotation/src/main/java/org/jeecgframework/poi/excel/annotation/ExcelVerify.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.annotation; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | /** 24 | * Excel 导入校验 25 | * 26 | * @author JueYue 27 | * @date 2014年6月23日 下午10:46:26 28 | */ 29 | @Retention(RetentionPolicy.RUNTIME) 30 | @Target(ElementType.FIELD) 31 | public @interface ExcelVerify { 32 | /** 33 | * 接口校验 34 | * @return 35 | */ 36 | public boolean interHandler() default false; 37 | 38 | /** 39 | * 是电子邮件 40 | * 41 | * @return 42 | */ 43 | public boolean isEmail() default false; 44 | 45 | /** 46 | * 是13位移动电话 47 | * 48 | * @return 49 | */ 50 | public boolean isMobile() default false; 51 | 52 | /** 53 | * 是座机号码 54 | * 55 | * @return 56 | */ 57 | public boolean isTel() default false; 58 | 59 | /** 60 | * 最大长度 61 | * 62 | * @return 63 | */ 64 | public int maxLength() default -1; 65 | 66 | /** 67 | * 最小长度 68 | * 69 | * @return 70 | */ 71 | public int minLength() default -1; 72 | 73 | /** 74 | * 不允许空 75 | * 76 | * @return 77 | */ 78 | public boolean notNull() default false; 79 | 80 | /** 81 | * 正在表达式 82 | * 83 | * @return 84 | */ 85 | public String regex() default ""; 86 | 87 | /** 88 | * 正在表达式,错误提示信息 89 | * 90 | * @return 91 | */ 92 | public String regexTip() default "数据不符合规范"; 93 | 94 | } 95 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/cache/manager/POICacheManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.cache.manager; 17 | 18 | import java.io.ByteArrayInputStream; 19 | import java.io.InputStream; 20 | import java.util.Arrays; 21 | import java.util.concurrent.ExecutionException; 22 | import java.util.concurrent.TimeUnit; 23 | 24 | import org.slf4j.Logger; 25 | import org.slf4j.LoggerFactory; 26 | 27 | import com.google.common.cache.CacheBuilder; 28 | import com.google.common.cache.CacheLoader; 29 | import com.google.common.cache.LoadingCache; 30 | 31 | /** 32 | * 缓存管理 33 | * 34 | * @author JueYue 35 | * @date 2014年2月10日 36 | * @version 1.0 37 | */ 38 | public final class POICacheManager { 39 | 40 | private static final Logger LOGGER = LoggerFactory 41 | .getLogger(POICacheManager.class); 42 | 43 | private static LoadingCache loadingCache; 44 | 45 | static { 46 | loadingCache = CacheBuilder.newBuilder().expireAfterWrite(7, TimeUnit.DAYS).maximumSize(50) 47 | .build(new CacheLoader() { 48 | @Override 49 | public byte[] load(String url) throws Exception { 50 | return new FileLoade().getFile(url); 51 | } 52 | }); 53 | } 54 | 55 | public static InputStream getFile(String id) { 56 | try { 57 | //复杂数据,防止操作原数据 58 | byte[] result = Arrays.copyOf(loadingCache.get(id), loadingCache.get(id).length); 59 | return new ByteArrayInputStream(result); 60 | } catch (ExecutionException e) { 61 | LOGGER.error(e.getMessage(),e); 62 | } 63 | return null; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/cache/ExcelCache.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.cache; 17 | 18 | import java.io.InputStream; 19 | import java.util.Arrays; 20 | import java.util.List; 21 | 22 | import org.apache.poi.openxml4j.exceptions.InvalidFormatException; 23 | import org.apache.poi.ss.usermodel.Workbook; 24 | import org.apache.poi.ss.usermodel.WorkbookFactory; 25 | import org.jeecgframework.poi.cache.manager.POICacheManager; 26 | import org.slf4j.Logger; 27 | import org.slf4j.LoggerFactory; 28 | 29 | /** 30 | * Excel类型的缓存 31 | * 32 | * @author JueYue 33 | * @date 2014年2月11日 34 | * @version 1.0 35 | */ 36 | public final class ExcelCache { 37 | 38 | private static final Logger LOGGER = LoggerFactory.getLogger(ExcelCache.class); 39 | 40 | public static Workbook getWorkbook(String url, Integer[] sheetNums, boolean needAll) { 41 | InputStream is = null; 42 | List sheetList = Arrays.asList(sheetNums); 43 | try { 44 | is = POICacheManager.getFile(url); 45 | Workbook wb = WorkbookFactory.create(is); 46 | // 删除其他的sheet 47 | if (!needAll) { 48 | for (int i = wb.getNumberOfSheets() - 1; i >= 0; i--) { 49 | if (!sheetList.contains(i)) { 50 | wb.removeSheetAt(i); 51 | } 52 | } 53 | } 54 | return wb; 55 | } catch (InvalidFormatException e) { 56 | LOGGER.error(e.getMessage(), e); 57 | } catch (Exception e) { 58 | LOGGER.error(e.getMessage(), e); 59 | } finally { 60 | try { 61 | is.close(); 62 | } catch (Exception e) { 63 | LOGGER.error(e.getMessage(), e); 64 | } 65 | } 66 | return null; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/word/entity/params/ListParamEntity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.word.entity.params; 17 | 18 | /** 19 | * Excel 对象导出结构 20 | * 21 | * @author JueYue 22 | * @date 2014年7月26日 下午11:14:48 23 | */ 24 | public class ListParamEntity { 25 | // 唯一值,在遍历中重复使用 26 | public static final String SINGLE = "single"; 27 | // 属于数组类型 28 | public static final String LIST = "list"; 29 | /** 30 | * 属性名称 31 | */ 32 | private String name; 33 | /** 34 | * 目标 35 | */ 36 | private String target; 37 | /** 38 | * 当是唯一值的时候直接求出值 39 | */ 40 | private Object value; 41 | /** 42 | * 数据类型,SINGLE || LIST 43 | */ 44 | private String type; 45 | 46 | public ListParamEntity() { 47 | 48 | } 49 | 50 | public ListParamEntity(String name, Object value) { 51 | this.name = name; 52 | this.value = value; 53 | this.type = LIST; 54 | } 55 | 56 | public ListParamEntity(String name, String target) { 57 | this.name = name; 58 | this.target = target; 59 | this.type = LIST; 60 | } 61 | 62 | public String getName() { 63 | return name; 64 | } 65 | 66 | public String getTarget() { 67 | return target; 68 | } 69 | 70 | public String getType() { 71 | return type; 72 | } 73 | 74 | public Object getValue() { 75 | return value; 76 | } 77 | 78 | public void setName(String name) { 79 | this.name = name; 80 | } 81 | 82 | public void setTarget(String target) { 83 | this.target = target; 84 | } 85 | 86 | public void setType(String type) { 87 | this.type = type; 88 | } 89 | 90 | public void setValue(Object value) { 91 | this.value = value; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/cache/manager/FileLoade.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.cache.manager; 17 | 18 | import java.io.ByteArrayOutputStream; 19 | import java.io.FileInputStream; 20 | import java.io.FileNotFoundException; 21 | import java.io.IOException; 22 | 23 | import org.jeecgframework.poi.util.PoiPublicUtil; 24 | import org.slf4j.Logger; 25 | import org.slf4j.LoggerFactory; 26 | 27 | /** 28 | * 文件加载类,根据路径加载指定文件 29 | * @author JueYue 30 | * @date 2014年2月10日 31 | * @version 1.0 32 | */ 33 | class FileLoade { 34 | 35 | private static final Logger LOGGER = LoggerFactory.getLogger(FileLoade.class); 36 | 37 | public byte[] getFile(String url) { 38 | FileInputStream fileis = null; 39 | ByteArrayOutputStream baos = null; 40 | try { 41 | //先用绝对路径查询,再查询相对路径 42 | try { 43 | fileis = new FileInputStream(url); 44 | } catch (FileNotFoundException e) { 45 | String path = PoiPublicUtil.getWebRootPath(url); 46 | fileis = new FileInputStream(path); 47 | } 48 | baos = new ByteArrayOutputStream(); 49 | byte[] buffer = new byte[1024]; 50 | int len; 51 | while ((len = fileis.read(buffer)) > -1) { 52 | baos.write(buffer, 0, len); 53 | } 54 | baos.flush(); 55 | return baos.toByteArray(); 56 | } catch (FileNotFoundException e) { 57 | LOGGER.error(e.getMessage(), e); 58 | } catch (IOException e) { 59 | LOGGER.error(e.getMessage(), e); 60 | } finally { 61 | try { 62 | if (fileis != null) 63 | fileis.close(); 64 | if (fileis != null) 65 | baos.close(); 66 | } catch (IOException e) { 67 | LOGGER.error(e.getMessage(), e); 68 | } 69 | } 70 | LOGGER.error(fileis + "这个路径文件没有找到,请查询"); 71 | return null; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/word/entity/WordImageEntity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.word.entity; 17 | 18 | /** 19 | * word导出,图片设置和图片信息 20 | * 21 | * @author JueYue 22 | * @date 2013-11-17 23 | * @version 1.0 24 | */ 25 | public class WordImageEntity { 26 | 27 | public static String URL = "url"; 28 | public static String Data = "data"; 29 | /** 30 | * 图片输入方式 31 | */ 32 | private String type = URL; 33 | /** 34 | * 图片宽度 35 | */ 36 | private int width; 37 | // 图片高度 38 | private int height; 39 | // 图片地址 40 | private String url; 41 | // 图片信息 42 | private byte[] data; 43 | 44 | public WordImageEntity() { 45 | 46 | } 47 | 48 | public WordImageEntity(byte[] data, int width, int height) { 49 | this.data = data; 50 | this.width = width; 51 | this.height = height; 52 | this.type = Data; 53 | } 54 | 55 | public WordImageEntity(String url, int width, int height) { 56 | this.url = url; 57 | this.width = width; 58 | this.height = height; 59 | } 60 | 61 | public byte[] getData() { 62 | return data; 63 | } 64 | 65 | public int getHeight() { 66 | return height; 67 | } 68 | 69 | public String getType() { 70 | return type; 71 | } 72 | 73 | public String getUrl() { 74 | return url; 75 | } 76 | 77 | public int getWidth() { 78 | return width; 79 | } 80 | 81 | public void setData(byte[] data) { 82 | this.data = data; 83 | } 84 | 85 | public void setHeight(int height) { 86 | this.height = height; 87 | } 88 | 89 | public void setType(String type) { 90 | this.type = type; 91 | } 92 | 93 | public void setUrl(String url) { 94 | this.url = url; 95 | } 96 | 97 | public void setWidth(int width) { 98 | this.width = width; 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/word/entity/params/ExcelListEntity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.word.entity.params; 17 | 18 | import java.util.List; 19 | 20 | import org.jeecgframework.poi.excel.entity.ExcelBaseParams; 21 | import org.jeecgframework.poi.handler.inter.IExcelDataHandler; 22 | 23 | /** 24 | * Excel 导出对象 25 | * 26 | * @author JueYue 27 | * @date 2014年8月9日 下午10:21:13 28 | */ 29 | public class ExcelListEntity extends ExcelBaseParams { 30 | 31 | /** 32 | * 数据源 33 | */ 34 | private List list; 35 | 36 | /** 37 | * 实体类对象 38 | */ 39 | private Class clazz; 40 | 41 | /** 42 | * 表头行数 43 | */ 44 | private int headRows = 1; 45 | 46 | public ExcelListEntity() { 47 | 48 | } 49 | 50 | public ExcelListEntity(List list, Class clazz) { 51 | this.list = list; 52 | this.clazz = clazz; 53 | } 54 | 55 | public ExcelListEntity(List list, Class clazz, IExcelDataHandler dataHanlder) { 56 | this.list = list; 57 | this.clazz = clazz; 58 | setDataHanlder(dataHanlder); 59 | } 60 | public ExcelListEntity(List list, Class clazz, IExcelDataHandler dataHanlder, int headRows) { 61 | this.list = list; 62 | this.clazz = clazz; 63 | this.headRows = headRows; 64 | setDataHanlder(dataHanlder); 65 | } 66 | public ExcelListEntity(List list, Class clazz, int headRows) { 67 | this.list = list; 68 | this.clazz = clazz; 69 | this.headRows = headRows; 70 | } 71 | 72 | public Class getClazz() { 73 | return clazz; 74 | } 75 | 76 | public int getHeadRows() { 77 | return headRows; 78 | } 79 | 80 | public List getList() { 81 | return list; 82 | } 83 | 84 | public void setClazz(Class clazz) { 85 | this.clazz = clazz; 86 | } 87 | 88 | public void setHeadRows(int headRows) { 89 | this.headRows = headRows; 90 | } 91 | 92 | public void setList(List list) { 93 | this.list = list; 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/styler/AbstractExcelExportStyler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.export.styler; 17 | 18 | import org.apache.poi.ss.usermodel.BuiltinFormats; 19 | import org.apache.poi.ss.usermodel.CellStyle; 20 | import org.apache.poi.ss.usermodel.Workbook; 21 | import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; 22 | 23 | /** 24 | * 抽象接口提供两个公共方法 25 | * @author JueYue 26 | * @date 2015年1月9日 下午5:48:55 27 | */ 28 | public abstract class AbstractExcelExportStyler implements IExcelExportStyler { 29 | //单行 30 | protected CellStyle stringNoneStyle; 31 | protected CellStyle stringNoneWrapStyle; 32 | //间隔行 33 | protected CellStyle stringSeptailStyle; 34 | protected CellStyle stringSeptailWrapStyle; 35 | 36 | protected Workbook workbook; 37 | 38 | protected static final short STRING_FORMAT = (short) BuiltinFormats.getBuiltinFormat("TEXT"); 39 | 40 | protected void createStyles(Workbook workbook) { 41 | this.stringNoneStyle = stringNoneStyle(workbook, false); 42 | this.stringNoneWrapStyle = stringNoneStyle(workbook, true); 43 | this.stringSeptailStyle = stringSeptailStyle(workbook, false); 44 | this.stringSeptailWrapStyle = stringSeptailStyle(workbook, true); 45 | this.workbook = workbook; 46 | } 47 | 48 | @Override 49 | public CellStyle getStyles(boolean noneStyler, ExcelExportEntity entity) { 50 | if (noneStyler && (entity == null || entity.isWrap())) { 51 | return stringNoneWrapStyle; 52 | } 53 | if (noneStyler) { 54 | return stringNoneStyle; 55 | } 56 | if (noneStyler == false && (entity == null || entity.isWrap())) { 57 | return stringSeptailWrapStyle; 58 | } 59 | return stringSeptailStyle; 60 | } 61 | 62 | public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) { 63 | return null; 64 | } 65 | 66 | public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) { 67 | return null; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/params/ExcelBaseEntity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.entity.params; 17 | 18 | import java.lang.reflect.Method; 19 | import java.util.List; 20 | 21 | /** 22 | * Excel 导入导出基础对象类 23 | * @author JueYue 24 | * @date 2014年6月20日 下午2:26:09 25 | */ 26 | public class ExcelBaseEntity { 27 | /** 28 | * 对应name 29 | */ 30 | protected String name; 31 | /** 32 | * 对应type 33 | */ 34 | private int type = 1; 35 | /** 36 | * 数据库格式 37 | */ 38 | private String databaseFormat; 39 | /** 40 | * 导出日期格式 41 | */ 42 | private String format; 43 | /** 44 | * 导出日期格式 45 | */ 46 | private String[] replace; 47 | /** 48 | * set/get方法 49 | */ 50 | private Method method; 51 | 52 | private List methods; 53 | 54 | public String getDatabaseFormat() { 55 | return databaseFormat; 56 | } 57 | 58 | public String getFormat() { 59 | return format; 60 | } 61 | 62 | public Method getMethod() { 63 | return method; 64 | } 65 | 66 | public List getMethods() { 67 | return methods; 68 | } 69 | 70 | public String getName() { 71 | return name; 72 | } 73 | 74 | public String[] getReplace() { 75 | return replace; 76 | } 77 | 78 | public int getType() { 79 | return type; 80 | } 81 | 82 | public void setDatabaseFormat(String databaseFormat) { 83 | this.databaseFormat = databaseFormat; 84 | } 85 | 86 | public void setFormat(String format) { 87 | this.format = format; 88 | } 89 | 90 | public void setMethod(Method method) { 91 | this.method = method; 92 | } 93 | 94 | public void setMethods(List methods) { 95 | this.methods = methods; 96 | } 97 | 98 | public void setName(String name) { 99 | this.name = name; 100 | } 101 | 102 | public void setReplace(String[] replace) { 103 | this.replace = replace; 104 | } 105 | 106 | public void setType(int type) { 107 | this.type = type; 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/helper/MergedRegionHelper.java: -------------------------------------------------------------------------------- 1 | package org.jeecgframework.poi.excel.html.helper; 2 | 3 | import java.util.HashMap; 4 | import java.util.HashSet; 5 | import java.util.Map; 6 | import java.util.Set; 7 | 8 | import org.apache.poi.ss.usermodel.Sheet; 9 | 10 | /** 11 | * 合并单元格帮助类 12 | * @author JueYue 13 | * @date 2015年5月9日 下午2:13:35 14 | */ 15 | public class MergedRegionHelper { 16 | 17 | private Map mergedCache = new HashMap(); 18 | 19 | private Set notNeedCread = new HashSet(); 20 | 21 | public MergedRegionHelper(Sheet sheet) { 22 | getAllMergedRegion(sheet); 23 | } 24 | 25 | private void getAllMergedRegion(Sheet sheet) { 26 | int nums = sheet.getNumMergedRegions(); 27 | for (int i = 0; i < nums; i++) { 28 | handerMergedString(sheet.getMergedRegion(i).formatAsString()); 29 | } 30 | } 31 | 32 | /** 33 | * 根据合并输出内容,处理合并单元格事情 34 | * @param formatAsString 35 | */ 36 | private void handerMergedString(String formatAsString) { 37 | String[] strArr = formatAsString.split(":"); 38 | if (strArr.length == 2) { 39 | int startCol = strArr[0].charAt(0) - 65; 40 | if (strArr[0].charAt(1) >= 65) { 41 | startCol = (startCol + 1) * 26 + (strArr[0].charAt(1) - 65); 42 | } 43 | int startRol = Integer.valueOf(strArr[0].substring(strArr[0].charAt(1) >= 65 ? 2 : 1)); 44 | int endCol = strArr[1].charAt(0) - 65; 45 | if (strArr[1].charAt(1) >= 65) { 46 | endCol = (endCol + 1) * 26 + (strArr[1].charAt(1) - 65); 47 | } 48 | int endRol = Integer.valueOf(strArr[1].substring(strArr[1].charAt(1) >= 65 ? 2 : 1)); 49 | mergedCache.put(startRol + "_" + startCol, new Integer[] { endRol - startRol + 1, 50 | endCol - startCol + 1 }); 51 | for (int i = startRol; i <= endRol; i++) { 52 | for (int j = startCol; j <= endCol; j++) { 53 | notNeedCread.add(i + "_" + j); 54 | } 55 | } 56 | notNeedCread.remove(startRol + "_" + startCol); 57 | } 58 | 59 | } 60 | 61 | /** 62 | * 是不是需要创建这个TD 63 | * @param row 64 | * @param col 65 | * @return 66 | */ 67 | public boolean isNeedCreate(int row, int col) { 68 | return !notNeedCread.contains(row + "_" + col); 69 | } 70 | 71 | /** 72 | * 是不是合并区域 73 | * @param row 74 | * @param col 75 | * @return 76 | */ 77 | public boolean isMergedRegion(int row, int col) { 78 | return mergedCache.containsKey(row + "_" + col); 79 | } 80 | 81 | /** 82 | * 获取合并区域 83 | * @param row 84 | * @param col 85 | * @return 86 | */ 87 | public Integer[] getRowAndColSpan(int row, int col) { 88 | return mergedCache.get(row + "_" + col); 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/styler/ExcelExportStylerDefaultImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.export.styler; 17 | 18 | import org.apache.poi.ss.usermodel.CellStyle; 19 | import org.apache.poi.ss.usermodel.Font; 20 | import org.apache.poi.ss.usermodel.Workbook; 21 | 22 | /** 23 | * 样式的默认实现 24 | * @author JueYue 25 | * @date 2015年1月9日 下午5:36:08 26 | */ 27 | public class ExcelExportStylerDefaultImpl extends AbstractExcelExportStyler implements 28 | IExcelExportStyler { 29 | 30 | public ExcelExportStylerDefaultImpl(Workbook workbook) { 31 | super.createStyles(workbook); 32 | } 33 | 34 | @Override 35 | public CellStyle getTitleStyle(short color) { 36 | CellStyle titleStyle = workbook.createCellStyle(); 37 | titleStyle.setAlignment(CellStyle.ALIGN_CENTER); 38 | titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); 39 | titleStyle.setWrapText(true); 40 | return titleStyle; 41 | } 42 | 43 | @Override 44 | public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) { 45 | CellStyle style = workbook.createCellStyle(); 46 | style.setAlignment(CellStyle.ALIGN_CENTER); 47 | style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); 48 | style.setDataFormat(STRING_FORMAT); 49 | if (isWarp) { 50 | style.setWrapText(true); 51 | } 52 | return style; 53 | } 54 | 55 | @Override 56 | public CellStyle getHeaderStyle(short color) { 57 | CellStyle titleStyle = workbook.createCellStyle(); 58 | Font font = workbook.createFont(); 59 | font.setFontHeightInPoints((short) 12); 60 | titleStyle.setFont(font); 61 | titleStyle.setAlignment(CellStyle.ALIGN_CENTER); 62 | titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); 63 | return titleStyle; 64 | } 65 | 66 | @Override 67 | public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) { 68 | CellStyle style = workbook.createCellStyle(); 69 | style.setAlignment(CellStyle.ALIGN_CENTER); 70 | style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); 71 | style.setDataFormat(STRING_FORMAT); 72 | if (isWarp) { 73 | style.setWrapText(true); 74 | } 75 | return style; 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/org/jeecgframework/poi/excel/view/JeecgTemplateWordView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.view; 17 | 18 | import java.util.Map; 19 | 20 | import javax.servlet.ServletOutputStream; 21 | import javax.servlet.http.HttpServletRequest; 22 | import javax.servlet.http.HttpServletResponse; 23 | 24 | import org.apache.poi.xwpf.usermodel.XWPFDocument; 25 | import org.jeecgframework.poi.excel.entity.vo.TemplateWordConstants; 26 | import org.jeecgframework.poi.word.WordExportUtil; 27 | import org.springframework.stereotype.Controller; 28 | import org.springframework.web.servlet.view.AbstractView; 29 | 30 | /** 31 | * Word模板视图 32 | * 33 | * @author JueYue 34 | * @date 2014年6月30日 下午9:15:49 35 | */ 36 | @SuppressWarnings("unchecked") 37 | @Controller(TemplateWordConstants.JEECG_TEMPLATE_WORD_VIEW) 38 | public class JeecgTemplateWordView extends AbstractView { 39 | 40 | private static final String CONTENT_TYPE = "application/msword"; 41 | 42 | public JeecgTemplateWordView() { 43 | setContentType(CONTENT_TYPE); 44 | } 45 | 46 | public boolean isIE(HttpServletRequest request) { 47 | return (request.getHeader("USER-AGENT").toLowerCase().indexOf("msie") > 0 || request 48 | .getHeader("USER-AGENT").toLowerCase().indexOf("rv:11.0") > 0) ? true : false; 49 | } 50 | 51 | @Override 52 | protected void renderMergedOutputModel(Map model, HttpServletRequest request, 53 | HttpServletResponse response) throws Exception { 54 | String codedFileName = "临时文件.docx"; 55 | if (model.containsKey(TemplateWordConstants.FILE_NAME)) { 56 | codedFileName = (String) model.get(TemplateWordConstants.FILE_NAME) + ".docx"; 57 | } 58 | if (isIE(request)) { 59 | codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8"); 60 | } else { 61 | codedFileName = new String(codedFileName.getBytes("UTF-8"), "ISO-8859-1"); 62 | } 63 | response.setHeader("content-disposition", "attachment;filename=" + codedFileName); 64 | XWPFDocument document = WordExportUtil.exportWord07( 65 | (String) model.get(TemplateWordConstants.URL), 66 | (Map) model.get(TemplateWordConstants.MAP_DATA)); 67 | ServletOutputStream out = response.getOutputStream(); 68 | document.write(out); 69 | out.flush(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/params/ExcelImportEntity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.entity.params; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * excel 导入工具类,对cell类型做映射 22 | * @author JueYue 23 | * @version 1.0 2013年8月24日 24 | */ 25 | public class ExcelImportEntity extends ExcelBaseEntity { 26 | /** 27 | * 对应 Collection NAME 28 | */ 29 | private String collectionName; 30 | /** 31 | * 保存图片的地址 32 | */ 33 | private String saveUrl; 34 | /** 35 | * 保存图片的类型,1是文件,2是数据库 36 | */ 37 | private int saveType; 38 | /** 39 | * 对应exportType 40 | */ 41 | private String classType; 42 | /** 43 | * 校驗參數 44 | */ 45 | private ExcelVerifyEntity verify; 46 | /** 47 | * 后缀 48 | */ 49 | private String suffix; 50 | 51 | private List list; 52 | 53 | public String getClassType() { 54 | return classType; 55 | } 56 | 57 | public String getCollectionName() { 58 | return collectionName; 59 | } 60 | 61 | public List getList() { 62 | return list; 63 | } 64 | 65 | public int getSaveType() { 66 | return saveType; 67 | } 68 | 69 | public String getSaveUrl() { 70 | return saveUrl; 71 | } 72 | 73 | public ExcelVerifyEntity getVerify() { 74 | return verify; 75 | } 76 | 77 | public void setClassType(String classType) { 78 | this.classType = classType; 79 | } 80 | 81 | public void setCollectionName(String collectionName) { 82 | this.collectionName = collectionName; 83 | } 84 | 85 | public void setList(List list) { 86 | this.list = list; 87 | } 88 | 89 | public void setSaveType(int saveType) { 90 | this.saveType = saveType; 91 | } 92 | 93 | public void setSaveUrl(String saveUrl) { 94 | this.saveUrl = saveUrl; 95 | } 96 | 97 | public void setVerify(ExcelVerifyEntity verify) { 98 | this.verify = verify; 99 | } 100 | 101 | public String getSuffix() { 102 | return suffix; 103 | } 104 | 105 | public void setSuffix(String suffix) { 106 | this.suffix = suffix; 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/org/jeecgframework/poi/excel/view/JeecgMapExcelView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.view; 17 | 18 | import java.util.Collection; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | import javax.servlet.ServletOutputStream; 23 | import javax.servlet.http.HttpServletRequest; 24 | import javax.servlet.http.HttpServletResponse; 25 | 26 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; 27 | import org.apache.poi.ss.usermodel.Workbook; 28 | import org.jeecgframework.poi.excel.ExcelExportUtil; 29 | import org.jeecgframework.poi.excel.entity.ExportParams; 30 | import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; 31 | import org.jeecgframework.poi.excel.entity.vo.MapExcelConstants; 32 | import org.springframework.stereotype.Controller; 33 | 34 | /** 35 | * Map 对象接口 36 | * 37 | * @author JueYue 38 | * @date 2014年11月25日 下午3:26:32 39 | */ 40 | @SuppressWarnings("unchecked") 41 | @Controller(MapExcelConstants.JEECG_MAP_EXCEL_VIEW) 42 | public class JeecgMapExcelView extends MiniAbstractExcelView { 43 | 44 | public JeecgMapExcelView() { 45 | super(); 46 | } 47 | 48 | @Override 49 | protected void renderMergedOutputModel(Map model, HttpServletRequest request, 50 | HttpServletResponse response) throws Exception { 51 | String codedFileName = "临时文件"; 52 | Workbook workbook = ExcelExportUtil.exportExcel( 53 | (ExportParams) model.get(MapExcelConstants.PARAMS), 54 | (List) model.get(MapExcelConstants.ENTITY_LIST), 55 | (Collection>) model.get(MapExcelConstants.MAP_LIST)); 56 | if (model.containsKey(MapExcelConstants.FILE_NAME)) { 57 | codedFileName = (String) model.get(MapExcelConstants.FILE_NAME); 58 | } 59 | if (workbook instanceof HSSFWorkbook) { 60 | codedFileName += HSSF; 61 | } else { 62 | codedFileName += XSSF; 63 | } 64 | if (isIE(request)) { 65 | codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8"); 66 | } else { 67 | codedFileName = new String(codedFileName.getBytes("UTF-8"), "ISO-8859-1"); 68 | } 69 | response.setHeader("content-disposition", "attachment;filename=" + codedFileName); 70 | ServletOutputStream out = response.getOutputStream(); 71 | workbook.write(out); 72 | out.flush(); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/org/jeecgframework/poi/excel/view/JeecgTemplateExcelView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.view; 17 | 18 | import java.util.List; 19 | import java.util.Map; 20 | 21 | import javax.servlet.ServletOutputStream; 22 | import javax.servlet.http.HttpServletRequest; 23 | import javax.servlet.http.HttpServletResponse; 24 | 25 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; 26 | import org.apache.poi.ss.usermodel.Workbook; 27 | import org.jeecgframework.poi.excel.ExcelExportUtil; 28 | import org.jeecgframework.poi.excel.entity.TemplateExportParams; 29 | import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants; 30 | import org.jeecgframework.poi.excel.entity.vo.TemplateExcelConstants; 31 | import org.springframework.stereotype.Controller; 32 | 33 | /** 34 | * Excel模板视图 35 | * 36 | * @author JueYue 37 | * @date 2014年6月30日 下午9:15:49 38 | */ 39 | @SuppressWarnings("unchecked") 40 | @Controller(TemplateExcelConstants.JEECG_TEMPLATE_EXCEL_VIEW) 41 | public class JeecgTemplateExcelView extends MiniAbstractExcelView { 42 | 43 | public JeecgTemplateExcelView() { 44 | super(); 45 | } 46 | 47 | @Override 48 | protected void renderMergedOutputModel(Map model, HttpServletRequest request, 49 | HttpServletResponse response) throws Exception { 50 | String codedFileName = "临时文件"; 51 | Workbook workbook = ExcelExportUtil.exportExcel( 52 | (TemplateExportParams) model.get(TemplateExcelConstants.PARAMS), 53 | (Class) model.get(TemplateExcelConstants.CLASS), 54 | (List) model.get(TemplateExcelConstants.LIST_DATA), 55 | (Map) model.get(TemplateExcelConstants.MAP_DATA)); 56 | if (model.containsKey(NormalExcelConstants.FILE_NAME)) { 57 | codedFileName = (String) model.get(NormalExcelConstants.FILE_NAME); 58 | } 59 | if (workbook instanceof HSSFWorkbook) { 60 | codedFileName += HSSF; 61 | } else { 62 | codedFileName += XSSF; 63 | } 64 | if (isIE(request)) { 65 | codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8"); 66 | } else { 67 | codedFileName = new String(codedFileName.getBytes("UTF-8"), "ISO-8859-1"); 68 | } 69 | response.setHeader("content-disposition", "attachment;filename=" + codedFileName); 70 | ServletOutputStream out = response.getOutputStream(); 71 | workbook.write(out); 72 | out.flush(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/word/parse/excel/ExcelMapParse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.word.parse.excel; 17 | 18 | import java.util.List; 19 | 20 | import org.apache.poi.xwpf.usermodel.XWPFTable; 21 | import org.apache.poi.xwpf.usermodel.XWPFTableCell; 22 | import org.apache.poi.xwpf.usermodel.XWPFTableRow; 23 | import org.jeecgframework.poi.util.PoiPublicUtil; 24 | 25 | /** 26 | * 处理和生成Map 类型的数据变成表格 27 | * @author JueYue 28 | * @date 2014年8月9日 下午10:28:46 29 | */ 30 | public final class ExcelMapParse { 31 | 32 | /** 33 | * 解析参数行,获取参数列表 34 | * 35 | * @Author JueYue 36 | * @date 2013-11-18 37 | * @param currentRow 38 | * @return 39 | */ 40 | private static String[] parseCurrentRowGetParams(XWPFTableRow currentRow) { 41 | List cells = currentRow.getTableCells(); 42 | String[] params = new String[cells.size()]; 43 | String text; 44 | for (int i = 0; i < cells.size(); i++) { 45 | text = cells.get(i).getText(); 46 | params[i] = text == null ? "" : text.trim().replace("{{", "").replace("}}", ""); 47 | } 48 | return params; 49 | } 50 | 51 | /** 52 | * 解析下一行,并且生成更多的行 53 | * 54 | * @Author JueYue 55 | * @date 2013-11-18 56 | * @param table 57 | * @param listobj2 58 | */ 59 | public static void parseNextRowAndAddRow(XWPFTable table, int index, List list) 60 | throws Exception { 61 | XWPFTableRow currentRow = table.getRow(index); 62 | String[] params = parseCurrentRowGetParams(currentRow); 63 | table.removeRow(index);// 移除这一行 64 | int cellIndex = 0;// 创建完成对象一行好像多了一个cell 65 | for (Object obj : list) { 66 | currentRow = table.createRow(); 67 | for (cellIndex = 0; cellIndex < currentRow.getTableCells().size(); cellIndex++) { 68 | currentRow 69 | .getTableCells() 70 | .get(cellIndex) 71 | .setText( 72 | PoiPublicUtil.getValueDoWhile(obj, params[cellIndex].split("\\."), 0) 73 | .toString()); 74 | } 75 | for (; cellIndex < params.length; cellIndex++) { 76 | currentRow.createCell().setText( 77 | PoiPublicUtil.getValueDoWhile(obj, params[cellIndex].split("\\."), 0) 78 | .toString()); 79 | } 80 | } 81 | 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/styler/ExcelExportStylerBorderImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.export.styler; 17 | 18 | import org.apache.poi.ss.usermodel.CellStyle; 19 | import org.apache.poi.ss.usermodel.Font; 20 | import org.apache.poi.ss.usermodel.Workbook; 21 | 22 | /** 23 | * 带有边框的Excel样式 24 | * @author JueYue 25 | * @date 2015年1月9日 下午5:55:29 26 | */ 27 | public class ExcelExportStylerBorderImpl extends AbstractExcelExportStyler implements 28 | IExcelExportStyler { 29 | 30 | public ExcelExportStylerBorderImpl(Workbook workbook) { 31 | super.createStyles(workbook); 32 | } 33 | 34 | @Override 35 | public CellStyle getHeaderStyle(short color) { 36 | CellStyle titleStyle = workbook.createCellStyle(); 37 | Font font = workbook.createFont(); 38 | font.setFontHeightInPoints((short) 12); 39 | titleStyle.setFont(font); 40 | titleStyle.setBorderLeft((short) 1); // 左边框 41 | titleStyle.setBorderRight((short) 1); // 右边框 42 | titleStyle.setBorderBottom((short) 1); 43 | titleStyle.setBorderTop((short) 1); 44 | titleStyle.setAlignment(CellStyle.ALIGN_CENTER); 45 | titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); 46 | return titleStyle; 47 | } 48 | 49 | @Override 50 | public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) { 51 | CellStyle style = workbook.createCellStyle(); 52 | style.setBorderLeft((short) 1); // 左边框 53 | style.setBorderRight((short) 1); // 右边框 54 | style.setBorderBottom((short) 1); 55 | style.setBorderTop((short) 1); 56 | style.setAlignment(CellStyle.ALIGN_CENTER); 57 | style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); 58 | style.setDataFormat(STRING_FORMAT); 59 | if (isWarp) { 60 | style.setWrapText(true); 61 | } 62 | return style; 63 | } 64 | 65 | @Override 66 | public CellStyle getTitleStyle(short color) { 67 | CellStyle titleStyle = workbook.createCellStyle(); 68 | titleStyle.setBorderLeft((short) 1); // 左边框 69 | titleStyle.setBorderRight((short) 1); // 右边框 70 | titleStyle.setBorderBottom((short) 1); 71 | titleStyle.setBorderTop((short) 1); 72 | titleStyle.setAlignment(CellStyle.ALIGN_CENTER); 73 | titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); 74 | titleStyle.setWrapText(true); 75 | return titleStyle; 76 | } 77 | 78 | @Override 79 | public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) { 80 | return isWarp ? stringNoneWrapStyle : stringNoneStyle; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /easypoi-annotation/src/main/java/org/jeecgframework/poi/excel/annotation/Excel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.annotation; 17 | 18 | import java.lang.annotation.ElementType; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.RetentionPolicy; 21 | import java.lang.annotation.Target; 22 | 23 | /** 24 | * Excel 导出基本注释 25 | * @author JueYue 26 | * @date 2014年6月20日 下午10:25:12 27 | */ 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target(ElementType.FIELD) 30 | public @interface Excel { 31 | 32 | /** 33 | * 导出时间设置,如果字段是Date类型则不需要设置 数据库如果是string 类型,这个需要设置这个数据库格式 34 | */ 35 | public String databaseFormat() default "yyyyMMddHHmmss"; 36 | 37 | /** 38 | * 导出的时间格式,以这个是否为空来判断是否需要格式化日期 39 | */ 40 | public String exportFormat() default ""; 41 | 42 | /** 43 | * 时间格式,相当于同时设置了exportFormat 和 importFormat 44 | */ 45 | public String format() default ""; 46 | 47 | /** 48 | * 导出时在excel中每个列的高度 单位为字符,一个汉字=2个字符 49 | */ 50 | public double height() default 10; 51 | 52 | /** 53 | * 导出类型 1 从file读取 2 是从数据库中读取 默认是文件 同样导入也是一样的 54 | */ 55 | public int imageType() default 1; 56 | 57 | /** 58 | * 导入的时间格式,以这个是否为空来判断是否需要格式化日期 59 | */ 60 | public String importFormat() default ""; 61 | 62 | /** 63 | * 文字后缀,如% 90 变成90% 64 | */ 65 | public String suffix() default ""; 66 | 67 | /** 68 | * 是否换行 即支持\n 69 | */ 70 | public boolean isWrap() default true; 71 | 72 | /** 73 | * 合并单元格依赖关系,比如第二列合并是基于第一列 则{1}就可以了 74 | */ 75 | public int[] mergeRely() default {}; 76 | 77 | /** 78 | * 纵向合并内容相同的单元格 79 | */ 80 | public boolean mergeVertical() default false; 81 | 82 | /** 83 | * 导出时,对应数据库的字段 主要是用户区分每个字段, 不能有annocation重名的 导出时的列名 84 | * 导出排序跟定义了annotation的字段的顺序有关 可以使用a_id,b_id来确实是否使用 85 | */ 86 | public String name(); 87 | 88 | /** 89 | * 是否需要纵向合并单元格(用于含有list中,单个的单元格,合并list创建的多个row) 90 | */ 91 | public boolean needMerge() default false; 92 | 93 | /** 94 | * 展示到第几个可以使用a_id,b_id来确定不同排序 95 | */ 96 | public String orderNum() default "0"; 97 | 98 | /** 99 | * 值得替换 导出是{a_id,b_id} 导入反过来,所以只用写一个 100 | */ 101 | public String[] replace() default {}; 102 | 103 | /** 104 | * 导入路径,如果是图片可以填写,默认是upload/className/ IconEntity这个类对应的就是upload/Icon/ 105 | * 106 | */ 107 | public String savePath() default "upload"; 108 | 109 | /** 110 | * 导出类型 1 是文本 2 是图片,3是函数 默认是文本 111 | */ 112 | public int type() default 1; 113 | 114 | /** 115 | * 导出时在excel中每个列的宽 单位为字符,一个汉字=2个字符 如 以列名列内容中较合适的长度 例如姓名列6 【姓名一般三个字】 116 | * 性别列4【男女占1,但是列标题两个汉字】 限制1-255 117 | */ 118 | public double width() default 10; 119 | 120 | /** 121 | * 是否自动统计数据,如果是统计,true的话在最后追加一行统计,把所有数据都和 122 | * 这个处理会吞没异常,请注意这一点 123 | * @return 124 | */ 125 | public boolean isStatistics() default false; 126 | } 127 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/imports/verifys/VerifyHandlerServer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.imports.verifys; 17 | 18 | import org.apache.commons.lang3.StringUtils; 19 | import org.jeecgframework.poi.excel.entity.params.ExcelVerifyEntity; 20 | import org.jeecgframework.poi.excel.entity.result.ExcelVerifyHanlderResult; 21 | import org.jeecgframework.poi.handler.inter.IExcelVerifyHandler; 22 | 23 | /** 24 | * 校验服务 25 | * 26 | * @author JueYue 27 | * @date 2014年6月29日 下午4:37:56 28 | */ 29 | public class VerifyHandlerServer { 30 | 31 | private final static ExcelVerifyHanlderResult DEFAULT_RESULT = new ExcelVerifyHanlderResult( 32 | true); 33 | 34 | private void addVerifyResult(ExcelVerifyHanlderResult hanlderResult, 35 | ExcelVerifyHanlderResult result) { 36 | if (!hanlderResult.isSuccess()) { 37 | result.setSuccess(false); 38 | result.setMsg((StringUtils.isEmpty(result.getMsg()) ? "" : result.getMsg() + " , ") 39 | + hanlderResult.getMsg()); 40 | } 41 | } 42 | 43 | /** 44 | * 校驗數據 45 | * 46 | * @param object 47 | * @param value 48 | * @param titleString 49 | * @param verify 50 | * @param excelVerifyHandler 51 | */ 52 | public ExcelVerifyHanlderResult verifyData(Object object, Object value, String name, 53 | ExcelVerifyEntity verify, 54 | IExcelVerifyHandler excelVerifyHandler) { 55 | if (verify == null) { 56 | return DEFAULT_RESULT; 57 | } 58 | ExcelVerifyHanlderResult result = new ExcelVerifyHanlderResult(true, ""); 59 | if (verify.isNotNull()) { 60 | addVerifyResult(BaseVerifyHandler.notNull(name, value), result); 61 | } 62 | if (verify.isEmail()) { 63 | addVerifyResult(BaseVerifyHandler.isEmail(name, value), result); 64 | } 65 | if (verify.isMobile()) { 66 | addVerifyResult(BaseVerifyHandler.isMobile(name, value), result); 67 | } 68 | if (verify.isTel()) { 69 | addVerifyResult(BaseVerifyHandler.isTel(name, value), result); 70 | } 71 | if (verify.getMaxLength() != -1) { 72 | addVerifyResult(BaseVerifyHandler.maxLength(name, value, verify.getMaxLength()), result); 73 | } 74 | if (verify.getMinLength() != -1) { 75 | addVerifyResult(BaseVerifyHandler.minLength(name, value, verify.getMinLength()), result); 76 | } 77 | if (StringUtils.isNotEmpty(verify.getRegex())) { 78 | addVerifyResult( 79 | BaseVerifyHandler.regex(name, value, verify.getRegex(), verify.getRegexTip()), 80 | result); 81 | } 82 | if (verify.isInterHandler()) { 83 | addVerifyResult(excelVerifyHandler.verifyHandler(object, name, value), result); 84 | } 85 | return result; 86 | 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/styler/ExcelExportStylerColorImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.export.styler; 17 | 18 | import org.apache.poi.ss.usermodel.CellStyle; 19 | import org.apache.poi.ss.usermodel.Font; 20 | import org.apache.poi.ss.usermodel.Workbook; 21 | 22 | /** 23 | * 带有样式的导出服务 24 | * @author JueYue 25 | * @date 2015年1月9日 下午4:54:15 26 | */ 27 | public class ExcelExportStylerColorImpl extends AbstractExcelExportStyler implements 28 | IExcelExportStyler { 29 | 30 | public ExcelExportStylerColorImpl(Workbook workbook) { 31 | super.createStyles(workbook); 32 | } 33 | 34 | @Override 35 | public CellStyle getHeaderStyle(short headerColor) { 36 | CellStyle titleStyle = workbook.createCellStyle(); 37 | Font font = workbook.createFont(); 38 | font.setFontHeightInPoints((short) 24); 39 | titleStyle.setFont(font); 40 | titleStyle.setFillForegroundColor(headerColor); 41 | titleStyle.setAlignment(CellStyle.ALIGN_CENTER); 42 | titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); 43 | return titleStyle; 44 | } 45 | 46 | @Override 47 | public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) { 48 | CellStyle style = workbook.createCellStyle(); 49 | style.setBorderLeft((short) 1); // 左边框 50 | style.setBorderRight((short) 1); // 右边框 51 | style.setBorderBottom((short) 1); 52 | style.setBorderTop((short) 1); 53 | style.setAlignment(CellStyle.ALIGN_CENTER); 54 | style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); 55 | style.setDataFormat(STRING_FORMAT); 56 | if (isWarp) { 57 | style.setWrapText(true); 58 | } 59 | return style; 60 | } 61 | 62 | @Override 63 | public CellStyle getTitleStyle(short color) { 64 | CellStyle titleStyle = workbook.createCellStyle(); 65 | titleStyle.setFillForegroundColor(color); // 填充的背景颜色 66 | titleStyle.setAlignment(CellStyle.ALIGN_CENTER); 67 | titleStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER); 68 | titleStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); // 填充图案 69 | titleStyle.setWrapText(true); 70 | return titleStyle; 71 | } 72 | 73 | @Override 74 | public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) { 75 | CellStyle style = workbook.createCellStyle(); 76 | style.setBorderLeft((short) 1); // 左边框 77 | style.setBorderRight((short) 1); // 右边框 78 | style.setBorderBottom((short) 1); 79 | style.setBorderTop((short) 1); 80 | style.setFillForegroundColor((short) 41); // 填充的背景颜色 81 | style.setFillPattern(CellStyle.SOLID_FOREGROUND); // 填充图案 82 | style.setAlignment(CellStyle.ALIGN_CENTER); 83 | style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); 84 | style.setDataFormat(STRING_FORMAT); 85 | if (isWarp) { 86 | style.setWrapText(true); 87 | } 88 | return style; 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/params/ExcelVerifyEntity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.entity.params; 17 | 18 | /** 19 | * Excel 校验对象 20 | * 21 | * @author JueYue 22 | * @date 2014年6月29日 下午4:24:59 23 | */ 24 | public class ExcelVerifyEntity { 25 | 26 | /** 27 | * 接口校验 28 | * 29 | * @return 30 | */ 31 | private boolean interHandler; 32 | 33 | /** 34 | * 不允许空 35 | * 36 | * @return 37 | */ 38 | private boolean notNull; 39 | 40 | /** 41 | * 是13位移动电话 42 | * 43 | * @return 44 | */ 45 | private boolean isMobile; 46 | /** 47 | * 是座机号码 48 | * 49 | * @return 50 | */ 51 | private boolean isTel; 52 | 53 | /** 54 | * 是电子邮件 55 | * 56 | * @return 57 | */ 58 | private boolean isEmail; 59 | 60 | /** 61 | * 最小长度 62 | * 63 | * @return 64 | */ 65 | private int minLength; 66 | 67 | /** 68 | * 最大长度 69 | * 70 | * @return 71 | */ 72 | private int maxLength; 73 | 74 | /** 75 | * 正在表达式 76 | * 77 | * @return 78 | */ 79 | private String regex; 80 | /** 81 | * 正在表达式,错误提示信息 82 | * 83 | * @return 84 | */ 85 | private String regexTip; 86 | 87 | public int getMaxLength() { 88 | return maxLength; 89 | } 90 | 91 | public int getMinLength() { 92 | return minLength; 93 | } 94 | 95 | public String getRegex() { 96 | return regex; 97 | } 98 | 99 | public String getRegexTip() { 100 | return regexTip; 101 | } 102 | 103 | public boolean isEmail() { 104 | return isEmail; 105 | } 106 | 107 | public boolean isInterHandler() { 108 | return interHandler; 109 | } 110 | 111 | public boolean isMobile() { 112 | return isMobile; 113 | } 114 | 115 | public boolean isNotNull() { 116 | return notNull; 117 | } 118 | 119 | public boolean isTel() { 120 | return isTel; 121 | } 122 | 123 | public void setEmail(boolean isEmail) { 124 | this.isEmail = isEmail; 125 | } 126 | 127 | public void setInterHandler(boolean interHandler) { 128 | this.interHandler = interHandler; 129 | } 130 | 131 | public void setMaxLength(int maxLength) { 132 | this.maxLength = maxLength; 133 | } 134 | 135 | public void setMinLength(int minLength) { 136 | this.minLength = minLength; 137 | } 138 | 139 | public void setMobile(boolean isMobile) { 140 | this.isMobile = isMobile; 141 | } 142 | 143 | public void setNotNull(boolean notNull) { 144 | this.notNull = notNull; 145 | } 146 | 147 | public void setRegex(String regex) { 148 | this.regex = regex; 149 | } 150 | 151 | public void setRegexTip(String regexTip) { 152 | this.regexTip = regexTip; 153 | } 154 | 155 | public void setTel(boolean isTel) { 156 | this.isTel = isTel; 157 | } 158 | 159 | } 160 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/util/PoiSheetUtility.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.util; 17 | 18 | import org.apache.poi.ss.usermodel.Cell; 19 | import org.apache.poi.ss.usermodel.Row; 20 | import org.apache.poi.ss.usermodel.Sheet; 21 | 22 | /** 23 | * 国外高手的,不过也不好,慎用,效率不行 24 | * Helper functions to aid in the management of sheets 25 | */ 26 | public class PoiSheetUtility extends Object { 27 | 28 | /** 29 | * Given a sheet, this method deletes a column from a sheet and moves 30 | * all the columns to the right of it to the left one cell. 31 | * 32 | * Note, this method will not update any formula references. 33 | * 34 | * @param sheet 35 | * @param column 36 | */ 37 | public static void deleteColumn(Sheet sheet, int columnToDelete) { 38 | int maxColumn = 0; 39 | for (int r = 0; r < sheet.getLastRowNum() + 1; r++) { 40 | Row row = sheet.getRow(r); 41 | 42 | // if no row exists here; then nothing to do; next! 43 | if (row == null) 44 | continue; 45 | 46 | // if the row doesn't have this many columns then we are good; next! 47 | int lastColumn = row.getLastCellNum(); 48 | if (lastColumn > maxColumn) 49 | maxColumn = lastColumn; 50 | 51 | if (lastColumn < columnToDelete) 52 | continue; 53 | 54 | for (int x = columnToDelete + 1; x < lastColumn + 1; x++) { 55 | Cell oldCell = row.getCell(x - 1); 56 | if (oldCell != null) 57 | row.removeCell(oldCell); 58 | 59 | Cell nextCell = row.getCell(x); 60 | if (nextCell != null) { 61 | Cell newCell = row.createCell(x - 1, nextCell.getCellType()); 62 | cloneCell(newCell, nextCell); 63 | } 64 | } 65 | } 66 | 67 | // Adjust the column widths 68 | for (int c = 0; c < maxColumn; c++) { 69 | sheet.setColumnWidth(c, sheet.getColumnWidth(c + 1)); 70 | } 71 | } 72 | 73 | /* 74 | * Takes an existing Cell and merges all the styles and forumla 75 | * into the new one 76 | */ 77 | private static void cloneCell(Cell cNew, Cell cOld) { 78 | cNew.setCellComment(cOld.getCellComment()); 79 | cNew.setCellStyle(cOld.getCellStyle()); 80 | 81 | switch (cNew.getCellType()) { 82 | case Cell.CELL_TYPE_BOOLEAN: { 83 | cNew.setCellValue(cOld.getBooleanCellValue()); 84 | break; 85 | } 86 | case Cell.CELL_TYPE_NUMERIC: { 87 | cNew.setCellValue(cOld.getNumericCellValue()); 88 | break; 89 | } 90 | case Cell.CELL_TYPE_STRING: { 91 | cNew.setCellValue(cOld.getStringCellValue()); 92 | break; 93 | } 94 | case Cell.CELL_TYPE_ERROR: { 95 | cNew.setCellValue(cOld.getErrorCellValue()); 96 | break; 97 | } 98 | case Cell.CELL_TYPE_FORMULA: { 99 | cNew.setCellFormula(cOld.getCellFormula()); 100 | break; 101 | } 102 | } 103 | 104 | } 105 | } -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/ImportParams.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.entity; 17 | 18 | import org.jeecgframework.poi.handler.inter.IExcelVerifyHandler; 19 | 20 | /** 21 | * 导入参数设置 22 | * 23 | * @author JueYue 24 | * @date 2013-9-24 25 | * @version 1.0 26 | */ 27 | public class ImportParams extends ExcelBaseParams { 28 | /** 29 | * 表格标题行数,默认0 30 | */ 31 | private int titleRows = 0; 32 | /** 33 | * 表头行数,默认1 34 | */ 35 | private int headRows = 1; 36 | /** 37 | * 字段真正值和列标题之间的距离 默认0 38 | */ 39 | private int startRows = 0; 40 | /** 41 | * 主键设置,如何这个cell没有值,就跳过 或者认为这个是list的下面的值 42 | */ 43 | private int keyIndex = 0; 44 | /** 45 | * 上传表格需要读取的sheet 数量,默认为1 46 | */ 47 | private int sheetNum = 1; 48 | /** 49 | * 是否需要保存上传的Excel,默认为false 50 | */ 51 | private boolean needSave = false; 52 | /** 53 | * 保存上传的Excel目录,默认是 如 TestEntity这个类保存路径就是 54 | * upload/excelUpload/Test/yyyyMMddHHmss_***** 保存名称上传时间_五位随机数 55 | */ 56 | private String saveUrl = "upload/excelUpload"; 57 | /** 58 | * 校验处理接口 59 | */ 60 | private IExcelVerifyHandler verifyHanlder; 61 | /** 62 | * 最后的无效行数 63 | */ 64 | private int lastOfInvalidRow = 0; 65 | 66 | public int getHeadRows() { 67 | return headRows; 68 | } 69 | 70 | public int getKeyIndex() { 71 | return keyIndex; 72 | } 73 | 74 | public String getSaveUrl() { 75 | return saveUrl; 76 | } 77 | 78 | public int getSheetNum() { 79 | return sheetNum; 80 | } 81 | 82 | public int getStartRows() { 83 | return startRows; 84 | } 85 | 86 | public int getTitleRows() { 87 | return titleRows; 88 | } 89 | 90 | public IExcelVerifyHandler getVerifyHanlder() { 91 | return verifyHanlder; 92 | } 93 | 94 | public boolean isNeedSave() { 95 | return needSave; 96 | } 97 | 98 | public void setHeadRows(int headRows) { 99 | this.headRows = headRows; 100 | } 101 | 102 | public void setKeyIndex(int keyIndex) { 103 | this.keyIndex = keyIndex; 104 | } 105 | 106 | public void setNeedSave(boolean needSave) { 107 | this.needSave = needSave; 108 | } 109 | 110 | public void setSaveUrl(String saveUrl) { 111 | this.saveUrl = saveUrl; 112 | } 113 | 114 | public void setSheetNum(int sheetNum) { 115 | this.sheetNum = sheetNum; 116 | } 117 | 118 | public void setStartRows(int startRows) { 119 | this.startRows = startRows; 120 | } 121 | 122 | public void setTitleRows(int titleRows) { 123 | this.titleRows = titleRows; 124 | } 125 | 126 | public void setVerifyHanlder(IExcelVerifyHandler verifyHanlder) { 127 | this.verifyHanlder = verifyHanlder; 128 | } 129 | 130 | public int getLastOfInvalidRow() { 131 | return lastOfInvalidRow; 132 | } 133 | 134 | public void setLastOfInvalidRow(int lastOfInvalidRow) { 135 | this.lastOfInvalidRow = lastOfInvalidRow; 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/imports/sax/SaxReadExcel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.imports.sax; 17 | 18 | import java.io.InputStream; 19 | import java.util.Iterator; 20 | import java.util.List; 21 | 22 | import org.apache.poi.openxml4j.opc.OPCPackage; 23 | import org.apache.poi.xssf.eventusermodel.XSSFReader; 24 | import org.apache.poi.xssf.model.SharedStringsTable; 25 | import org.jeecgframework.poi.excel.entity.ImportParams; 26 | import org.jeecgframework.poi.excel.imports.sax.parse.ISaxRowRead; 27 | import org.jeecgframework.poi.excel.imports.sax.parse.SaxRowRead; 28 | import org.jeecgframework.poi.exception.excel.ExcelImportException; 29 | import org.jeecgframework.poi.handler.inter.IExcelReadRowHanlder; 30 | import org.slf4j.Logger; 31 | import org.slf4j.LoggerFactory; 32 | import org.xml.sax.ContentHandler; 33 | import org.xml.sax.InputSource; 34 | import org.xml.sax.SAXException; 35 | import org.xml.sax.XMLReader; 36 | import org.xml.sax.helpers.XMLReaderFactory; 37 | 38 | /** 39 | * 基于SAX Excel大数据读取,读取Excel 07版本,不支持图片读取 40 | * @author JueYue 41 | * @date 2014年12月29日 下午9:41:38 42 | * @version 1.0 43 | */ 44 | @SuppressWarnings("rawtypes") 45 | public class SaxReadExcel { 46 | 47 | private static final Logger LOGGER = LoggerFactory.getLogger(SaxReadExcel.class); 48 | 49 | public List readExcel(InputStream inputstream, Class pojoClass, ImportParams params, 50 | ISaxRowRead rowRead, IExcelReadRowHanlder hanlder) { 51 | try { 52 | OPCPackage opcPackage = OPCPackage.open(inputstream); 53 | return readExcel(opcPackage, pojoClass, params, rowRead, hanlder); 54 | } catch (Exception e) { 55 | LOGGER.error(e.getMessage(), e); 56 | throw new ExcelImportException(e.getMessage()); 57 | } 58 | } 59 | 60 | private List readExcel(OPCPackage opcPackage, Class pojoClass, ImportParams params, 61 | ISaxRowRead rowRead, IExcelReadRowHanlder hanlder) { 62 | try { 63 | XSSFReader xssfReader = new XSSFReader(opcPackage); 64 | SharedStringsTable sst = xssfReader.getSharedStringsTable(); 65 | if (rowRead == null) { 66 | rowRead = new SaxRowRead(pojoClass, params, hanlder); 67 | } 68 | XMLReader parser = fetchSheetParser(sst, rowRead); 69 | Iterator sheets = xssfReader.getSheetsData(); 70 | int sheetIndex = 0; 71 | while (sheets.hasNext() && sheetIndex < params.getSheetNum()) { 72 | sheetIndex++; 73 | InputStream sheet = sheets.next(); 74 | InputSource sheetSource = new InputSource(sheet); 75 | parser.parse(sheetSource); 76 | sheet.close(); 77 | } 78 | return rowRead.getList(); 79 | } catch (Exception e) { 80 | LOGGER.error(e.getMessage(), e); 81 | throw new ExcelImportException("SAX导入数据失败"); 82 | } 83 | } 84 | 85 | private XMLReader fetchSheetParser(SharedStringsTable sst, ISaxRowRead rowRead) 86 | throws SAXException { 87 | XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser"); 88 | ContentHandler handler = new SheetHandler(sst, rowRead); 89 | parser.setContentHandler(handler); 90 | return parser; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/org/jeecgframework/poi/excel/view/JeecgSingleExcelView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.view; 17 | 18 | import java.util.Collection; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | import javax.servlet.ServletOutputStream; 23 | import javax.servlet.http.HttpServletRequest; 24 | import javax.servlet.http.HttpServletResponse; 25 | 26 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; 27 | import org.apache.poi.ss.usermodel.Workbook; 28 | import org.jeecgframework.poi.excel.ExcelExportUtil; 29 | import org.jeecgframework.poi.excel.entity.ExportParams; 30 | import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants; 31 | import org.jeecgframework.poi.excel.export.ExcelExportServer; 32 | import org.springframework.stereotype.Controller; 33 | 34 | /** 35 | * @Author JueYue on 14-3-8. Excel 生成解析器,减少用户操作 36 | */ 37 | @SuppressWarnings("unchecked") 38 | @Controller(NormalExcelConstants.JEECG_EXCEL_VIEW) 39 | public class JeecgSingleExcelView extends MiniAbstractExcelView { 40 | 41 | public JeecgSingleExcelView() { 42 | super(); 43 | } 44 | 45 | @Override 46 | protected void renderMergedOutputModel(Map model, HttpServletRequest request, 47 | HttpServletResponse response) throws Exception { 48 | String codedFileName = "临时文件"; 49 | Workbook workbook = null; 50 | if (model.containsKey(NormalExcelConstants.MAP_LIST)) { 51 | List> list = (List>) model 52 | .get(NormalExcelConstants.MAP_LIST); 53 | if (list.size() == 0) { 54 | throw new RuntimeException("MAP_LIST IS NULL"); 55 | } 56 | workbook = ExcelExportUtil.exportExcel( 57 | (ExportParams) list.get(0).get(NormalExcelConstants.PARAMS), (Class) list.get(0) 58 | .get(NormalExcelConstants.CLASS), 59 | (Collection) list.get(0).get(NormalExcelConstants.DATA_LIST)); 60 | for (int i = 1; i < list.size(); i++) { 61 | new ExcelExportServer().createSheet(workbook, 62 | (ExportParams) list.get(i).get(NormalExcelConstants.PARAMS), (Class) list 63 | .get(i).get(NormalExcelConstants.CLASS), 64 | (Collection) list.get(i).get(NormalExcelConstants.DATA_LIST)); 65 | } 66 | } else { 67 | workbook = ExcelExportUtil.exportExcel( 68 | (ExportParams) model.get(NormalExcelConstants.PARAMS), 69 | (Class) model.get(NormalExcelConstants.CLASS), 70 | (Collection) model.get(NormalExcelConstants.DATA_LIST)); 71 | } 72 | if (model.containsKey(NormalExcelConstants.FILE_NAME)) { 73 | codedFileName = (String) model.get(NormalExcelConstants.FILE_NAME); 74 | } 75 | if (workbook instanceof HSSFWorkbook) { 76 | codedFileName += HSSF; 77 | } else { 78 | codedFileName += XSSF; 79 | } 80 | if (isIE(request)) { 81 | codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8"); 82 | } else { 83 | codedFileName = new String(codedFileName.getBytes("UTF-8"), "ISO-8859-1"); 84 | } 85 | response.setHeader("content-disposition", "attachment;filename=" + codedFileName); 86 | ServletOutputStream out = response.getOutputStream(); 87 | workbook.write(out); 88 | out.flush(); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/imports/verifys/BaseVerifyHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.imports.verifys; 17 | 18 | import java.util.regex.Pattern; 19 | 20 | import org.jeecgframework.poi.excel.entity.result.ExcelVerifyHanlderResult; 21 | 22 | /** 23 | * 基础校验工具类 24 | * 25 | * @author JueYue 26 | * @date 2014年6月23日 下午11:10:12 27 | */ 28 | public class BaseVerifyHandler { 29 | 30 | private static String NOT_NULL = "不允许为空"; 31 | private static String IS_MOBILE = "不是手机号"; 32 | private static String IS_TEL = "不是电话号码"; 33 | private static String IS_EMAIL = "不是邮箱地址"; 34 | private static String MIN_LENGHT = "小于规定长度"; 35 | private static String MAX_LENGHT = "超过规定长度"; 36 | 37 | private static Pattern mobilePattern = Pattern.compile("^[1][3,4,5,8,7][0-9]{9}$"); 38 | 39 | private static Pattern telPattern = Pattern.compile("^([0][1-9]{2,3}-)?[0-9]{5,10}$"); 40 | 41 | private static Pattern emailPattern = Pattern 42 | .compile("^([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+\\.[a-zA-Z]{2,3}$"); 43 | 44 | /** 45 | * email校验 46 | * 47 | * @param name 48 | * @param val 49 | * @return 50 | */ 51 | public static ExcelVerifyHanlderResult isEmail(String name, Object val) { 52 | if (!emailPattern.matcher(String.valueOf(val)).matches()) { 53 | return new ExcelVerifyHanlderResult(false, name + IS_EMAIL); 54 | } 55 | return new ExcelVerifyHanlderResult(true); 56 | } 57 | 58 | /** 59 | * 手机校验 60 | * 61 | * @param name 62 | * @param val 63 | * @return 64 | */ 65 | public static ExcelVerifyHanlderResult isMobile(String name, Object val) { 66 | if (!mobilePattern.matcher(String.valueOf(val)).matches()) { 67 | return new ExcelVerifyHanlderResult(false, name + IS_MOBILE); 68 | } 69 | return new ExcelVerifyHanlderResult(true); 70 | } 71 | 72 | /** 73 | * 电话校验 74 | * 75 | * @param name 76 | * @param val 77 | * @return 78 | */ 79 | public static ExcelVerifyHanlderResult isTel(String name, Object val) { 80 | if (!telPattern.matcher(String.valueOf(val)).matches()) { 81 | return new ExcelVerifyHanlderResult(false, name + IS_TEL); 82 | } 83 | return new ExcelVerifyHanlderResult(true); 84 | } 85 | 86 | /** 87 | * 最大长度校验 88 | * 89 | * @param name 90 | * @param val 91 | * @return 92 | */ 93 | public static ExcelVerifyHanlderResult maxLength(String name, Object val, int maxLength) { 94 | if (notNull(name, val).isSuccess() && String.valueOf(val).length() > maxLength) { 95 | return new ExcelVerifyHanlderResult(false, name + MAX_LENGHT); 96 | } 97 | return new ExcelVerifyHanlderResult(true); 98 | } 99 | 100 | /** 101 | * 最小长度校验 102 | * 103 | * @param name 104 | * @param val 105 | * @param minLength 106 | * @return 107 | */ 108 | public static ExcelVerifyHanlderResult minLength(String name, Object val, int minLength) { 109 | if (notNull(name, val).isSuccess() && String.valueOf(val).length() < minLength) { 110 | return new ExcelVerifyHanlderResult(false, name + MIN_LENGHT); 111 | } 112 | return new ExcelVerifyHanlderResult(true); 113 | } 114 | 115 | /** 116 | * 非空校验 117 | * 118 | * @param name 119 | * @param val 120 | * @return 121 | */ 122 | public static ExcelVerifyHanlderResult notNull(String name, Object val) { 123 | if (val == null || val.toString().equals("")) { 124 | return new ExcelVerifyHanlderResult(false, name + NOT_NULL); 125 | } 126 | return new ExcelVerifyHanlderResult(true); 127 | } 128 | 129 | /** 130 | * 正则表达式校验 131 | * @param name 132 | * @param val 133 | * @param regex 134 | * @param regexTip 135 | * @return 136 | */ 137 | public static ExcelVerifyHanlderResult regex(String name, Object val, String regex, 138 | String regexTip) { 139 | Pattern pattern = Pattern.compile(regex); 140 | if (!pattern.matcher(String.valueOf(val)).matches()) { 141 | return new ExcelVerifyHanlderResult(false, name + regexTip); 142 | } 143 | return new ExcelVerifyHanlderResult(true); 144 | } 145 | 146 | } 147 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/params/ExcelExportEntity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.entity.params; 17 | 18 | import java.util.List; 19 | 20 | /** 21 | * excel 导出工具类,对cell类型做映射 22 | * 23 | * @author JueYue 24 | * @version 1.0 2013年8月24日 25 | */ 26 | public class ExcelExportEntity extends ExcelBaseEntity implements Comparable { 27 | 28 | /** 29 | * 如果是MAP导出,这个是map的key 30 | */ 31 | private Object key; 32 | 33 | private double width = 10; 34 | 35 | private double height = 10; 36 | 37 | /** 38 | * 图片的类型,1是文件,2是数据库 39 | */ 40 | private int exportImageType = 0; 41 | 42 | /** 43 | * 排序顺序 44 | */ 45 | private int orderNum = 0; 46 | 47 | /** 48 | * 是否支持换行 49 | */ 50 | private boolean isWrap; 51 | 52 | /** 53 | * 是否需要合并 54 | */ 55 | private boolean needMerge; 56 | /** 57 | * 单元格纵向合并 58 | */ 59 | private boolean mergeVertical; 60 | /** 61 | * 合并依赖 62 | */ 63 | private int[] mergeRely; 64 | /** 65 | * 后缀 66 | */ 67 | private String suffix; 68 | /** 69 | * 统计 70 | */ 71 | private boolean isStatistics; 72 | 73 | private List list; 74 | 75 | public ExcelExportEntity() { 76 | 77 | } 78 | 79 | public ExcelExportEntity(String name) { 80 | super.name = name; 81 | } 82 | 83 | public ExcelExportEntity(String name, Object key) { 84 | super.name = name; 85 | this.key = key; 86 | } 87 | 88 | public ExcelExportEntity(String name, Object key, int width) { 89 | super.name = name; 90 | this.width = width; 91 | this.key = key; 92 | } 93 | 94 | public int getExportImageType() { 95 | return exportImageType; 96 | } 97 | 98 | public double getHeight() { 99 | return height; 100 | } 101 | 102 | public Object getKey() { 103 | return key; 104 | } 105 | 106 | public List getList() { 107 | return list; 108 | } 109 | 110 | public int[] getMergeRely() { 111 | return mergeRely == null ? new int[0] : mergeRely; 112 | } 113 | 114 | public int getOrderNum() { 115 | return orderNum; 116 | } 117 | 118 | public double getWidth() { 119 | return width; 120 | } 121 | 122 | public boolean isMergeVertical() { 123 | return mergeVertical; 124 | } 125 | 126 | public boolean isNeedMerge() { 127 | return needMerge; 128 | } 129 | 130 | public boolean isWrap() { 131 | return isWrap; 132 | } 133 | 134 | public void setExportImageType(int exportImageType) { 135 | this.exportImageType = exportImageType; 136 | } 137 | 138 | public void setHeight(double height) { 139 | this.height = height; 140 | } 141 | 142 | public void setKey(Object key) { 143 | this.key = key; 144 | } 145 | 146 | public void setList(List list) { 147 | this.list = list; 148 | } 149 | 150 | public void setMergeRely(int[] mergeRely) { 151 | this.mergeRely = mergeRely; 152 | } 153 | 154 | public void setMergeVertical(boolean mergeVertical) { 155 | this.mergeVertical = mergeVertical; 156 | } 157 | 158 | public void setNeedMerge(boolean needMerge) { 159 | this.needMerge = needMerge; 160 | } 161 | 162 | public void setOrderNum(int orderNum) { 163 | this.orderNum = orderNum; 164 | } 165 | 166 | public void setWidth(double width) { 167 | this.width = width; 168 | } 169 | 170 | public void setWrap(boolean isWrap) { 171 | this.isWrap = isWrap; 172 | } 173 | 174 | public String getSuffix() { 175 | return suffix; 176 | } 177 | 178 | public void setSuffix(String suffix) { 179 | this.suffix = suffix; 180 | } 181 | 182 | public boolean isStatistics() { 183 | return isStatistics; 184 | } 185 | 186 | public void setStatistics(boolean isStatistics) { 187 | this.isStatistics = isStatistics; 188 | } 189 | 190 | @Override 191 | public int compareTo(ExcelExportEntity prev) { 192 | return this.getOrderNum() - prev.getOrderNum(); 193 | } 194 | 195 | } 196 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/ExcelExportUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel; 17 | 18 | import java.util.Collection; 19 | import java.util.List; 20 | import java.util.Map; 21 | 22 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; 23 | import org.apache.poi.ss.usermodel.Workbook; 24 | import org.apache.poi.xssf.streaming.SXSSFWorkbook; 25 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 26 | import org.jeecgframework.poi.excel.entity.ExportParams; 27 | import org.jeecgframework.poi.excel.entity.TemplateExportParams; 28 | import org.jeecgframework.poi.excel.entity.enmus.ExcelType; 29 | import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; 30 | import org.jeecgframework.poi.excel.export.ExcelExportServer; 31 | import org.jeecgframework.poi.excel.export.template.ExcelExportOfTemplateUtil; 32 | 33 | /** 34 | * excel 导出工具类 35 | * 36 | * @author JueYue 37 | * @version 1.0 38 | * @date 2013-10-17 39 | */ 40 | public final class ExcelExportUtil { 41 | 42 | private ExcelExportUtil() { 43 | } 44 | 45 | /** 46 | * @param entity 47 | * 表格标题属性 48 | * @param pojoClass 49 | * Excel对象Class 50 | * @param dataSet 51 | * Excel对象数据List 52 | */ 53 | public static Workbook exportExcel(ExportParams entity, Class pojoClass, 54 | Collection dataSet) { 55 | Workbook workbook; 56 | if (ExcelType.HSSF.equals(entity.getType())) { 57 | workbook = new HSSFWorkbook(); 58 | } else if (dataSet.size() < 1000) { 59 | workbook = new XSSFWorkbook(); 60 | } else { 61 | workbook = new SXSSFWorkbook(); 62 | } 63 | new ExcelExportServer().createSheet(workbook, entity, pojoClass, dataSet); 64 | return workbook; 65 | } 66 | 67 | /** 68 | * 根据Map创建对应的Excel 69 | * @param entity 70 | * 表格标题属性 71 | * @param pojoClass 72 | * Excel对象Class 73 | * @param dataSet 74 | * Excel对象数据List 75 | */ 76 | public static Workbook exportExcel(ExportParams entity, List entityList, 77 | Collection> dataSet) { 78 | Workbook workbook; 79 | if (ExcelType.HSSF.equals(entity.getType())) { 80 | workbook = new HSSFWorkbook(); 81 | } else if (dataSet.size() < 1000) { 82 | workbook = new XSSFWorkbook(); 83 | } else { 84 | workbook = new SXSSFWorkbook(); 85 | } 86 | new ExcelExportServer().createSheetForMap(workbook, entity, entityList, dataSet); 87 | return workbook; 88 | } 89 | 90 | /** 91 | * 一个excel 创建多个sheet 92 | * 93 | * @param list 94 | * 多个Map key title 对应表格Title key entity 对应表格对应实体 key data 95 | * Collection 数据 96 | * @return 97 | */ 98 | public static Workbook exportExcel(List> list, String type) { 99 | Workbook workbook; 100 | if (ExcelType.HSSF.equals(type)) { 101 | workbook = new HSSFWorkbook(); 102 | } else { 103 | workbook = new XSSFWorkbook(); 104 | } 105 | for (Map map : list) { 106 | ExcelExportServer server = new ExcelExportServer(); 107 | server.createSheet(workbook, (ExportParams) map.get("title"), 108 | (Class) map.get("entity"), (Collection) map.get("data")); 109 | } 110 | return workbook; 111 | } 112 | 113 | /** 114 | * 导出文件通过模板解析,不推荐这个了,推荐全部通过模板来执行处理 115 | * 116 | * @param params 117 | * 导出参数类 118 | * @param pojoClass 119 | * 对应实体 120 | * @param dataSet 121 | * 实体集合 122 | * @param map 123 | * 模板集合 124 | * @return 125 | */ 126 | public static Workbook exportExcel(TemplateExportParams params, Class pojoClass, 127 | Collection dataSet, Map map) { 128 | return new ExcelExportOfTemplateUtil().createExcleByTemplate(params, pojoClass, dataSet, 129 | map); 130 | } 131 | 132 | /** 133 | * 导出文件通过模板解析只有模板,没有集合 134 | * 135 | * @param params 136 | * 导出参数类 137 | * @param map 138 | * 模板集合 139 | * @return 140 | */ 141 | public static Workbook exportExcel(TemplateExportParams params, Map map) { 142 | return new ExcelExportOfTemplateUtil().createExcleByTemplate(params, null, null, map); 143 | } 144 | 145 | } 146 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/imports/sax/SheetHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.imports.sax; 17 | 18 | import java.math.BigDecimal; 19 | import java.util.Date; 20 | import java.util.List; 21 | 22 | import org.apache.poi.hssf.usermodel.HSSFDateUtil; 23 | import org.apache.poi.xssf.model.SharedStringsTable; 24 | import org.apache.poi.xssf.usermodel.XSSFRichTextString; 25 | import org.jeecgframework.poi.excel.entity.enmus.CellValueType; 26 | import org.jeecgframework.poi.excel.entity.sax.SaxReadCellEntity; 27 | import org.jeecgframework.poi.excel.imports.sax.parse.ISaxRowRead; 28 | import org.xml.sax.Attributes; 29 | import org.xml.sax.SAXException; 30 | import org.xml.sax.helpers.DefaultHandler; 31 | 32 | import com.google.common.collect.Lists; 33 | 34 | /** 35 | * 回调接口 36 | * @author JueYue 37 | * @date 2014年12月29日 下午9:50:09 38 | */ 39 | public class SheetHandler extends DefaultHandler { 40 | 41 | private SharedStringsTable sst; 42 | private String lastContents; 43 | 44 | //当前行 45 | private int curRow = 0; 46 | //当前列 47 | private int curCol = 0; 48 | 49 | private CellValueType type; 50 | 51 | private ISaxRowRead read; 52 | 53 | //存储行记录的容器 54 | private List rowlist = Lists.newArrayList(); 55 | 56 | public SheetHandler(SharedStringsTable sst, ISaxRowRead rowRead) { 57 | this.sst = sst; 58 | this.read = rowRead; 59 | } 60 | 61 | @Override 62 | public void startElement(String uri, String localName, String name, Attributes attributes) 63 | throws SAXException { 64 | // 置空 65 | lastContents = ""; 66 | // c => 单元格 67 | if ("c".equals(name)) { 68 | // 如果下一个元素是 SST 的索引,则将nextIsString标记为true 69 | String cellType = attributes.getValue("t"); 70 | if ("s".equals(cellType)) { 71 | type = CellValueType.String; 72 | return; 73 | } 74 | //日期格式 75 | cellType = attributes.getValue("s"); 76 | if ("1".equals(cellType)) { 77 | type = CellValueType.Date; 78 | } else if ("2".equals(cellType)) { 79 | type = CellValueType.Number; 80 | } 81 | } else if ("t".equals(name)) {//当元素为t时 82 | type = CellValueType.TElement; 83 | } 84 | 85 | } 86 | 87 | @Override 88 | public void endElement(String uri, String localName, String name) throws SAXException { 89 | 90 | // 根据SST的索引值的到单元格的真正要存储的字符串 91 | // 这时characters()方法可能会被调用多次 92 | if (CellValueType.String.equals(type)) { 93 | try { 94 | int idx = Integer.parseInt(lastContents); 95 | lastContents = new XSSFRichTextString(sst.getEntryAt(idx)).toString(); 96 | } catch (Exception e) { 97 | 98 | } 99 | } 100 | //t元素也包含字符串 101 | if (CellValueType.TElement.equals(type)) { 102 | String value = lastContents.trim(); 103 | rowlist.add(curCol, new SaxReadCellEntity(CellValueType.String, value)); 104 | curCol++; 105 | type = CellValueType.None; 106 | // v => 单元格的值,如果单元格是字符串则v标签的值为该字符串在SST中的索引 107 | // 将单元格内容加入rowlist中,在这之前先去掉字符串前后的空白符 108 | } else if ("v".equals(name)) { 109 | String value = lastContents.trim(); 110 | value = value.equals("") ? " " : value; 111 | if (CellValueType.Date.equals(type)) { 112 | Date date = HSSFDateUtil.getJavaDate(Double.valueOf(value)); 113 | rowlist.add(curCol, new SaxReadCellEntity(CellValueType.Date, date)); 114 | } else if (CellValueType.Number.equals(type)) { 115 | BigDecimal bd = new BigDecimal(value); 116 | rowlist.add(curCol, new SaxReadCellEntity(CellValueType.Number, bd)); 117 | } else if (CellValueType.String.equals(type)) { 118 | rowlist.add(curCol, new SaxReadCellEntity(CellValueType.String, value)); 119 | } 120 | curCol++; 121 | } else if (name.equals("row")) {//如果标签名称为 row ,这说明已到行尾,调用 optRows() 方法 122 | read.parse(curRow, rowlist); 123 | rowlist.clear(); 124 | curRow++; 125 | curCol = 0; 126 | } 127 | 128 | } 129 | 130 | @Override 131 | public void characters(char[] ch, int start, int length) throws SAXException { 132 | //得到单元格内容的值 133 | lastContents += new String(ch, start, length); 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/helper/CellValueHelper.java: -------------------------------------------------------------------------------- 1 | package org.jeecgframework.poi.excel.html.helper; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.apache.poi.hssf.usermodel.HSSFRichTextString; 7 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; 8 | import org.apache.poi.ss.usermodel.Cell; 9 | import org.apache.poi.ss.usermodel.Font; 10 | import org.apache.poi.ss.usermodel.Workbook; 11 | import org.apache.poi.xssf.usermodel.XSSFFont; 12 | import org.apache.poi.xssf.usermodel.XSSFRichTextString; 13 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 14 | 15 | import com.google.common.xml.XmlEscapers; 16 | 17 | /** 18 | * Cell值帮助类 19 | * @author JueYue 20 | * @date 2015年5月9日 下午10:31:32 21 | */ 22 | public class CellValueHelper { 23 | /** 24 | * Excel 格式 25 | */ 26 | private boolean is07; 27 | 28 | private int cssRandom; 29 | 30 | private Map fontCache = new HashMap(); 31 | 32 | public CellValueHelper(Workbook wb, int cssRandom) { 33 | this.cssRandom = cssRandom; 34 | if (wb instanceof HSSFWorkbook) 35 | is07 = false; 36 | else if (wb instanceof XSSFWorkbook) { 37 | is07 = true; 38 | cacheFontInfo(wb); 39 | } else 40 | throw new IllegalArgumentException("unknown workbook type: " 41 | + wb.getClass().getSimpleName()); 42 | } 43 | 44 | /** 45 | * O7 版本坑爹bug 46 | * @param wb 47 | */ 48 | private void cacheFontInfo(Workbook wb) { 49 | for (short i = 0, le = wb.getNumberOfFonts(); i < le; i++) { 50 | Font font = wb.getFontAt(i); 51 | fontCache.put(font.getBoldweight() + "_" + font.getItalic() + "_" + font.getFontName() 52 | + "_" + font.getFontHeightInPoints() + "_" + font.getColor(), 53 | font.getIndex() + ""); 54 | } 55 | 56 | } 57 | 58 | public String getHtmlValue(Cell cell) { 59 | if (Cell.CELL_TYPE_BOOLEAN == cell.getCellType() 60 | || Cell.CELL_TYPE_NUMERIC == cell.getCellType()) { 61 | cell.setCellType(Cell.CELL_TYPE_STRING); 62 | return cell.getStringCellValue(); 63 | } else if (Cell.CELL_TYPE_STRING == cell.getCellType()) { 64 | if (cell.getRichStringCellValue().numFormattingRuns() == 0) { 65 | return XmlEscapers.xmlContentEscaper().escape(cell.getStringCellValue()); 66 | } else if (is07) { 67 | return getXSSFRichString((XSSFRichTextString) cell.getRichStringCellValue()); 68 | } else { 69 | return getHSSFRichString((HSSFRichTextString) cell.getRichStringCellValue()); 70 | } 71 | } 72 | return ""; 73 | } 74 | 75 | /** 76 | * 03版本复杂数据 77 | * @param rich 78 | * @return 79 | */ 80 | private String getHSSFRichString(HSSFRichTextString rich) { 81 | int nums = rich.numFormattingRuns(); 82 | StringBuilder sb = new StringBuilder(); 83 | String text = rich.toString(); 84 | int currentIndex = 0; 85 | sb.append(text.substring(0, rich.getIndexOfFormattingRun(0))); 86 | for (int i = 0; i < nums; i++) { 87 | sb.append(""); 92 | currentIndex = rich.getIndexOfFormattingRun(i); 93 | if (i < nums - 1) { 94 | sb.append(XmlEscapers.xmlContentEscaper().escape( 95 | text.substring(currentIndex, rich.getIndexOfFormattingRun(i + 1)))); 96 | } else { 97 | sb.append(XmlEscapers.xmlContentEscaper().escape( 98 | text.substring(currentIndex, text.length()))); 99 | } 100 | sb.append(""); 101 | } 102 | return sb.toString(); 103 | } 104 | 105 | /** 106 | * 07版本复杂数据 107 | * @param rich 108 | * @return 109 | */ 110 | private String getXSSFRichString(XSSFRichTextString rich) { 111 | int nums = rich.numFormattingRuns(); 112 | StringBuilder sb = new StringBuilder(); 113 | String text = rich.toString(); 114 | int currentIndex = 0, lastIndex = 0; 115 | for (int i = 1; i <= nums; i++) { 116 | sb.append(""); 125 | currentIndex = rich.getIndexOfFormattingRun(i) == -1 ? text.length() : rich 126 | .getIndexOfFormattingRun(i); 127 | sb.append(XmlEscapers.xmlContentEscaper().escape( 128 | text.substring(lastIndex, currentIndex))); 129 | sb.append(""); 130 | lastIndex = currentIndex; 131 | } 132 | return sb.toString(); 133 | } 134 | 135 | private String getFontIndex(XSSFFont font) { 136 | return fontCache.get(font.getBoldweight() + "_" + font.getItalic() + "_" 137 | + font.getFontName() + "_" + font.getFontHeightInPoints() + "_" 138 | + font.getColor()); 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/TemplateExportParams.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.entity; 17 | 18 | import org.jeecgframework.poi.excel.export.styler.ExcelExportStylerDefaultImpl; 19 | 20 | /** 21 | * 模板导出参数设置 22 | * 23 | * @author JueYue 24 | * @date 2013-10-17 25 | * @version 1.0 26 | */ 27 | public class TemplateExportParams extends ExcelBaseParams { 28 | 29 | /** 30 | * 输出全部的sheet 31 | */ 32 | private boolean scanAllsheet = false; 33 | /** 34 | * 模板的路径 35 | */ 36 | private String templateUrl; 37 | 38 | /** 39 | * 需要导出的第几个 sheetNum,默认是第0个 40 | */ 41 | private Integer[] sheetNum = new Integer[] { 0 }; 42 | 43 | /** 44 | * 这只sheetName 不填就使用原来的 45 | */ 46 | private String[] sheetName; 47 | 48 | /** 49 | * 表格列标题行数,默认1 50 | */ 51 | private int headingRows = 1; 52 | 53 | /** 54 | * 表格列标题开始行,默认1 55 | */ 56 | private int headingStartRow = 1; 57 | /** 58 | * 设置数据源的NUM 59 | */ 60 | private int dataSheetNum = 0; 61 | /** 62 | * Excel 导出style 63 | */ 64 | private Class style = ExcelExportStylerDefaultImpl.class; 65 | /** 66 | * FOR EACH 用到的局部变量 67 | */ 68 | private String tempParams = "t"; 69 | 70 | /** 71 | * 默认构造器 72 | */ 73 | public TemplateExportParams() { 74 | 75 | } 76 | 77 | /** 78 | * 构造器 79 | * @param templateUrl 模板路径 80 | * @param scanAllsheet 是否输出全部的sheet 81 | * @param sheetName sheet的名称,可不填 82 | */ 83 | public TemplateExportParams(String templateUrl, boolean scanAllsheet, String... sheetName) { 84 | this.templateUrl = templateUrl; 85 | this.scanAllsheet = scanAllsheet; 86 | if (sheetName != null && sheetName.length > 0) { 87 | this.sheetName = sheetName; 88 | 89 | } 90 | } 91 | 92 | /** 93 | * 构造器 94 | * @param templateUrl 模板路径 95 | * @param sheetNum sheet 的位置,可不填 96 | */ 97 | public TemplateExportParams(String templateUrl, Integer... sheetNum) { 98 | this.templateUrl = templateUrl; 99 | if (sheetNum != null && sheetNum.length > 0) { 100 | this.sheetNum = sheetNum; 101 | } 102 | } 103 | 104 | /** 105 | * 单个sheet输出构造器 106 | * @param templateUrl 模板路径 107 | * @param sheetName sheet的名称 108 | * @param sheetNum sheet的位置,可不填 109 | */ 110 | public TemplateExportParams(String templateUrl, String sheetName, Integer... sheetNum) { 111 | this.templateUrl = templateUrl; 112 | this.sheetName = new String[] { sheetName }; 113 | if (sheetNum != null && sheetNum.length > 0) { 114 | this.sheetNum = sheetNum; 115 | } 116 | } 117 | 118 | public int getHeadingRows() { 119 | return headingRows; 120 | } 121 | 122 | public int getHeadingStartRow() { 123 | return headingStartRow; 124 | } 125 | 126 | public String[] getSheetName() { 127 | return sheetName; 128 | } 129 | 130 | public Integer[] getSheetNum() { 131 | return sheetNum; 132 | } 133 | 134 | public String getTemplateUrl() { 135 | return templateUrl; 136 | } 137 | 138 | public void setHeadingRows(int headingRows) { 139 | this.headingRows = headingRows; 140 | } 141 | 142 | public void setHeadingStartRow(int headingStartRow) { 143 | this.headingStartRow = headingStartRow; 144 | } 145 | 146 | public void setSheetName(String[] sheetName) { 147 | this.sheetName = sheetName; 148 | } 149 | 150 | public void setSheetName(String sheetName) { 151 | this.sheetName = new String[] { sheetName }; 152 | } 153 | 154 | public void setSheetNum(Integer[] sheetNum) { 155 | this.sheetNum = sheetNum; 156 | } 157 | 158 | public void setSheetNum(Integer sheetNum) { 159 | this.sheetNum = new Integer[] { sheetNum }; 160 | } 161 | 162 | public void setTemplateUrl(String templateUrl) { 163 | this.templateUrl = templateUrl; 164 | } 165 | 166 | public Class getStyle() { 167 | return style; 168 | } 169 | 170 | public void setStyle(Class style) { 171 | this.style = style; 172 | } 173 | 174 | public int getDataSheetNum() { 175 | return dataSheetNum; 176 | } 177 | 178 | public void setDataSheetNum(int dataSheetNum) { 179 | this.dataSheetNum = dataSheetNum; 180 | } 181 | 182 | public boolean isScanAllsheet() { 183 | return scanAllsheet; 184 | } 185 | 186 | public void setScanAllsheet(boolean scanAllsheet) { 187 | this.scanAllsheet = scanAllsheet; 188 | } 189 | 190 | public String getTempParams() { 191 | return tempParams; 192 | } 193 | 194 | public void setTempParams(String tempParams) { 195 | this.tempParams = tempParams; 196 | } 197 | 198 | } 199 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/util/PoiFunctionUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.util; 17 | 18 | import java.lang.reflect.Array; 19 | import java.text.DecimalFormat; 20 | import java.text.SimpleDateFormat; 21 | import java.util.Collection; 22 | import java.util.Map; 23 | 24 | import org.jeecgframework.poi.exception.excel.ExcelExportException; 25 | 26 | /** 27 | * if else,length,for each,fromatNumber,formatDate 28 | * 满足模板的 el 表达式支持 29 | * @author JueYue 30 | * @date 2015年4月24日 下午8:04:02 31 | */ 32 | public final class PoiFunctionUtil { 33 | 34 | private static final String TWO_DECIMAL_STR = "###.00"; 35 | private static final String THREE_DECIMAL_STR = "###.000"; 36 | 37 | private static final DecimalFormat TWO_DECIMAL = new DecimalFormat(TWO_DECIMAL_STR); 38 | private static final DecimalFormat THREE_DECIMAL = new DecimalFormat(THREE_DECIMAL_STR); 39 | 40 | private static final String DAY_STR = "yyyy-MM-dd"; 41 | private static final String TIME_STR = "yyyy-MM-dd HH:mm:ss"; 42 | private static final String TIME__NO_S_STR = "yyyy-MM-dd HH:mm"; 43 | 44 | private static final SimpleDateFormat DAY_FORMAT = new SimpleDateFormat(DAY_STR); 45 | private static final SimpleDateFormat TIME_FORMAT = new SimpleDateFormat(TIME_STR); 46 | private static final SimpleDateFormat TIME__NO_S_FORMAT = new SimpleDateFormat(TIME__NO_S_STR); 47 | 48 | private PoiFunctionUtil() { 49 | } 50 | 51 | /** 52 | * 获取对象的长度 53 | * @param obj 54 | * @return 55 | */ 56 | @SuppressWarnings("rawtypes") 57 | public static int length(Object obj) { 58 | if (obj == null) { 59 | return 0; 60 | } 61 | if (obj instanceof Map) { 62 | return ((Map) obj).size(); 63 | } 64 | if (obj instanceof Collection) { 65 | return ((Collection) obj).size(); 66 | } 67 | if (obj.getClass().isArray()) { 68 | return Array.getLength(obj); 69 | } 70 | return String.valueOf(obj).length(); 71 | } 72 | 73 | /** 74 | * 格式化数字 75 | * @param obj 76 | * @throws NumberFormatException 77 | * @return 78 | */ 79 | public static String formatNumber(Object obj, String format) { 80 | if (obj == null || obj.toString() == "") { 81 | return ""; 82 | } 83 | double number = Double.valueOf(obj.toString()); 84 | DecimalFormat decimalFormat = null; 85 | if (TWO_DECIMAL.equals(format)) { 86 | decimalFormat = TWO_DECIMAL; 87 | } else if (THREE_DECIMAL_STR.equals(format)) { 88 | decimalFormat = THREE_DECIMAL; 89 | } else { 90 | decimalFormat = new DecimalFormat(format); 91 | } 92 | return decimalFormat.format(number); 93 | } 94 | 95 | /** 96 | * 格式化时间 97 | * @param obj 98 | * @return 99 | */ 100 | public static String formatDate(Object obj, String format) { 101 | if (obj == null || obj.toString() == "") { 102 | return ""; 103 | } 104 | SimpleDateFormat dateFormat = null; 105 | if (DAY_STR.equals(format)) { 106 | dateFormat = DAY_FORMAT; 107 | } else if (TIME_STR.equals(format)) { 108 | dateFormat = TIME_FORMAT; 109 | } else if (TIME__NO_S_STR.equals(format)) { 110 | dateFormat = TIME__NO_S_FORMAT; 111 | } else { 112 | dateFormat = new SimpleDateFormat(format); 113 | } 114 | return dateFormat.format(obj); 115 | } 116 | 117 | /** 118 | * 判断是不是成功 119 | * @param first 120 | * @param operator 121 | * @param second 122 | * @return 123 | */ 124 | public static boolean isTrue(Object first, String operator, Object second) { 125 | if (">".endsWith(operator)) { 126 | return isGt(first, second); 127 | } else if ("<".endsWith(operator)) { 128 | return isGt(second, first); 129 | } else if ("==".endsWith(operator)) { 130 | if (first != null && second != null) { 131 | return first.equals(second); 132 | } 133 | return first == second; 134 | } else if ("!=".endsWith(operator)) { 135 | if (first != null && second != null) { 136 | return !first.equals(second); 137 | } 138 | return first != second; 139 | } else { 140 | throw new ExcelExportException("占不支持改操作符"); 141 | } 142 | } 143 | 144 | /** 145 | * 前者是不是大于后者 146 | * @param first 147 | * @param second 148 | * @return 149 | */ 150 | private static boolean isGt(Object first, Object second) { 151 | if (first == null || first.toString() == "") { 152 | return false; 153 | } 154 | if (second == null || second.toString() == "") { 155 | return true; 156 | } 157 | double one = Double.valueOf(first.toString()); 158 | double two = Double.valueOf(second.toString()); 159 | return one > two; 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/entity/ExportParams.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel.entity; 17 | 18 | import org.apache.poi.hssf.util.HSSFColor; 19 | import org.jeecgframework.poi.excel.entity.enmus.ExcelType; 20 | import org.jeecgframework.poi.excel.export.styler.ExcelExportStylerDefaultImpl; 21 | 22 | /** 23 | * Excel 导出参数 24 | * 25 | * @author JueYue 26 | * @version 1.0 2013年8月24日 27 | */ 28 | public class ExportParams extends ExcelBaseParams { 29 | 30 | /** 31 | * 表格名称 32 | */ 33 | private String title; 34 | 35 | /** 36 | * 表格名称 37 | */ 38 | private short titleHeight = 10; 39 | 40 | /** 41 | * 第二行名称 42 | */ 43 | private String secondTitle; 44 | 45 | /** 46 | * 表格名称 47 | */ 48 | private short secondTitleHeight = 8; 49 | /** 50 | * sheetName 51 | */ 52 | private String sheetName; 53 | /** 54 | * 过滤的属性 55 | */ 56 | private String[] exclusions; 57 | /** 58 | * 是否添加需要需要 59 | */ 60 | private boolean addIndex; 61 | /** 62 | * 是否添加需要需要 63 | */ 64 | private String indexName = "序号"; 65 | /** 66 | * 冰冻列 67 | */ 68 | private int freezeCol; 69 | /** 70 | * 表头颜色 71 | */ 72 | private short color = HSSFColor.WHITE.index; 73 | /** 74 | * 属性说明行的颜色 例如:HSSFColor.SKY_BLUE.index 默认 75 | */ 76 | private short headerColor = HSSFColor.SKY_BLUE.index; 77 | /** 78 | * Excel 导出版本 79 | */ 80 | private ExcelType type = ExcelType.HSSF; 81 | /** 82 | * Excel 导出style 83 | */ 84 | private Class style = ExcelExportStylerDefaultImpl.class; 85 | /** 86 | * 是否创建表头 87 | */ 88 | private boolean isCreateHeadRows = true; 89 | 90 | public ExportParams() { 91 | 92 | } 93 | 94 | public ExportParams(String title, String sheetName) { 95 | this.title = title; 96 | this.sheetName = sheetName; 97 | } 98 | 99 | public ExportParams(String title, String sheetName, ExcelType type) { 100 | this.title = title; 101 | this.sheetName = sheetName; 102 | this.type = type; 103 | } 104 | 105 | public ExportParams(String title, String secondTitle, String sheetName) { 106 | this.title = title; 107 | this.secondTitle = secondTitle; 108 | this.sheetName = sheetName; 109 | } 110 | 111 | public short getColor() { 112 | return color; 113 | } 114 | 115 | public String[] getExclusions() { 116 | return exclusions; 117 | } 118 | 119 | public short getHeaderColor() { 120 | return headerColor; 121 | } 122 | 123 | public String getSecondTitle() { 124 | return secondTitle; 125 | } 126 | 127 | public short getSecondTitleHeight() { 128 | return (short) (secondTitleHeight * 50); 129 | } 130 | 131 | public String getSheetName() { 132 | return sheetName; 133 | } 134 | 135 | public String getTitle() { 136 | return title; 137 | } 138 | 139 | public short getTitleHeight() { 140 | return (short) (titleHeight * 50); 141 | } 142 | 143 | public boolean isAddIndex() { 144 | return addIndex; 145 | } 146 | 147 | public void setAddIndex(boolean addIndex) { 148 | this.addIndex = addIndex; 149 | } 150 | 151 | public void setColor(short color) { 152 | this.color = color; 153 | } 154 | 155 | public void setExclusions(String[] exclusions) { 156 | this.exclusions = exclusions; 157 | } 158 | 159 | public void setHeaderColor(short headerColor) { 160 | this.headerColor = headerColor; 161 | } 162 | 163 | public void setSecondTitle(String secondTitle) { 164 | this.secondTitle = secondTitle; 165 | } 166 | 167 | public void setSecondTitleHeight(short secondTitleHeight) { 168 | this.secondTitleHeight = secondTitleHeight; 169 | } 170 | 171 | public void setSheetName(String sheetName) { 172 | this.sheetName = sheetName; 173 | } 174 | 175 | public void setTitle(String title) { 176 | this.title = title; 177 | } 178 | 179 | public void setTitleHeight(short titleHeight) { 180 | this.titleHeight = titleHeight; 181 | } 182 | 183 | public ExcelType getType() { 184 | return type; 185 | } 186 | 187 | public void setType(ExcelType type) { 188 | this.type = type; 189 | } 190 | 191 | public String getIndexName() { 192 | return indexName; 193 | } 194 | 195 | public void setIndexName(String indexName) { 196 | this.indexName = indexName; 197 | } 198 | 199 | public Class getStyle() { 200 | return style; 201 | } 202 | 203 | public void setStyle(Class style) { 204 | this.style = style; 205 | } 206 | 207 | public int getFreezeCol() { 208 | return freezeCol; 209 | } 210 | 211 | public void setFreezeCol(int freezeCol) { 212 | this.freezeCol = freezeCol; 213 | } 214 | 215 | public boolean isCreateHeadRows() { 216 | return isCreateHeadRows; 217 | } 218 | 219 | public void setCreateHeadRows(boolean isCreateHeadRows) { 220 | this.isCreateHeadRows = isCreateHeadRows; 221 | } 222 | 223 | } 224 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/word/entity/MyXWPFDocument.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.word.entity; 17 | 18 | import java.io.InputStream; 19 | 20 | import org.apache.poi.openxml4j.opc.OPCPackage; 21 | import org.apache.poi.xwpf.usermodel.XWPFDocument; 22 | import org.apache.poi.xwpf.usermodel.XWPFRun; 23 | import org.apache.xmlbeans.XmlException; 24 | import org.apache.xmlbeans.XmlToken; 25 | import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps; 26 | import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D; 27 | import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline; 28 | import org.slf4j.Logger; 29 | import org.slf4j.LoggerFactory; 30 | 31 | /** 32 | * 扩充document,修复图片插入失败问题问题 33 | * 34 | * @author JueYue 35 | * @date 2013-11-20 36 | * @version 1.0 37 | */ 38 | public class MyXWPFDocument extends XWPFDocument { 39 | 40 | private static final Logger LOGGER = LoggerFactory.getLogger(MyXWPFDocument.class); 41 | 42 | private static String PICXML = "" 43 | + "" 44 | + " " 45 | + " " 46 | + " " 47 | + " " 48 | + " " 49 | + " " 50 | + " " 51 | + " " 52 | + " " 53 | + " " 54 | + " " + " " 55 | + " " + " " 56 | + " " 57 | + " " 58 | + " " 59 | + " " 60 | + " " 61 | + " " + " " 62 | + " " + " " 63 | + ""; 64 | 65 | public MyXWPFDocument() { 66 | super(); 67 | } 68 | 69 | public MyXWPFDocument(InputStream in) throws Exception { 70 | super(in); 71 | } 72 | 73 | public MyXWPFDocument(OPCPackage opcPackage) throws Exception { 74 | super(opcPackage); 75 | } 76 | 77 | public void createPicture(String blipId, int id, int width, int height) { 78 | final int EMU = 9525; 79 | width *= EMU; 80 | height *= EMU; 81 | CTInline inline = createParagraph().createRun().getCTR().addNewDrawing().addNewInline(); 82 | String picXml = String.format(PICXML, id, blipId, width, height); 83 | XmlToken xmlToken = null; 84 | try { 85 | xmlToken = XmlToken.Factory.parse(picXml); 86 | } catch (XmlException xe) { 87 | LOGGER.error(xe.getMessage(), xe.fillInStackTrace()); 88 | } 89 | inline.set(xmlToken); 90 | 91 | inline.setDistT(0); 92 | inline.setDistB(0); 93 | inline.setDistL(0); 94 | inline.setDistR(0); 95 | 96 | CTPositiveSize2D extent = inline.addNewExtent(); 97 | extent.setCx(width); 98 | extent.setCy(height); 99 | 100 | CTNonVisualDrawingProps docPr = inline.addNewDocPr(); 101 | docPr.setId(id); 102 | docPr.setName("Picture " + id); 103 | docPr.setDescr("Generated"); 104 | } 105 | 106 | public void createPicture(XWPFRun run, String blipId, int id, int width, int height) { 107 | final int EMU = 9525; 108 | width *= EMU; 109 | height *= EMU; 110 | CTInline inline = run.getCTR().addNewDrawing().addNewInline(); 111 | String picXml = String.format(PICXML, id, blipId, width, height); 112 | XmlToken xmlToken = null; 113 | try { 114 | xmlToken = XmlToken.Factory.parse(picXml); 115 | } catch (XmlException xe) { 116 | LOGGER.error(xe.getMessage(), xe.fillInStackTrace()); 117 | } 118 | inline.set(xmlToken); 119 | 120 | inline.setDistT(0); 121 | inline.setDistB(0); 122 | inline.setDistL(0); 123 | inline.setDistR(0); 124 | 125 | CTPositiveSize2D extent = inline.addNewExtent(); 126 | extent.setCx(width); 127 | extent.setCy(height); 128 | 129 | CTNonVisualDrawingProps docPr = inline.addNewDocPr(); 130 | docPr.setId(id); 131 | docPr.setName("Picture " + id); 132 | docPr.setDescr("Generated"); 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/ExcelImportUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.jeecgframework.poi.excel; 17 | 18 | import java.io.File; 19 | import java.io.FileInputStream; 20 | import java.io.IOException; 21 | import java.io.InputStream; 22 | import java.util.List; 23 | 24 | import org.jeecgframework.poi.excel.entity.ImportParams; 25 | import org.jeecgframework.poi.excel.entity.result.ExcelImportResult; 26 | import org.jeecgframework.poi.excel.imports.ExcelImportServer; 27 | import org.jeecgframework.poi.excel.imports.sax.SaxReadExcel; 28 | import org.jeecgframework.poi.excel.imports.sax.parse.ISaxRowRead; 29 | import org.jeecgframework.poi.handler.inter.IExcelReadRowHanlder; 30 | import org.slf4j.Logger; 31 | import org.slf4j.LoggerFactory; 32 | 33 | /** 34 | * Excel 导入工具 35 | * 36 | * @author JueYue 37 | * @date 2013-9-24 38 | * @version 1.0 39 | */ 40 | @SuppressWarnings({ "unchecked" }) 41 | public final class ExcelImportUtil { 42 | 43 | private ExcelImportUtil() { 44 | } 45 | 46 | private static final Logger LOGGER = LoggerFactory.getLogger(ExcelImportUtil.class); 47 | 48 | /** 49 | * Excel 导入 数据源本地文件,不返回校验结果 导入 字 段类型 Integer,Long,Double,Date,String,Boolean 50 | * 51 | * @param file 52 | * @param pojoClass 53 | * @param params 54 | * @return 55 | * @throws Exception 56 | */ 57 | public static List importExcel(File file, Class pojoClass, ImportParams params) { 58 | FileInputStream in = null; 59 | List result = null; 60 | try { 61 | in = new FileInputStream(file); 62 | result = new ExcelImportServer().importExcelByIs(in, pojoClass, params).getList(); 63 | } catch (Exception e) { 64 | LOGGER.error(e.getMessage(), e); 65 | } finally { 66 | try { 67 | in.close(); 68 | } catch (IOException e) { 69 | LOGGER.error(e.getMessage(), e); 70 | } 71 | } 72 | return result; 73 | } 74 | 75 | /** 76 | * Excel 导入 数据源IO流,不返回校验结果 导入 字段类型 Integer,Long,Double,Date,String,Boolean 77 | * 78 | * @param file 79 | * @param pojoClass 80 | * @param params 81 | * @return 82 | * @throws Exception 83 | */ 84 | public static List importExcel(InputStream inputstream, Class pojoClass, 85 | ImportParams params) throws Exception { 86 | return new ExcelImportServer().importExcelByIs(inputstream, pojoClass, params).getList(); 87 | } 88 | 89 | /** 90 | * Excel 导入 数据源IO流,返回校验结果 字段类型 Integer,Long,Double,Date,String,Boolean 91 | * 92 | * @param file 93 | * @param pojoClass 94 | * @param params 95 | * @return 96 | * @throws Exception 97 | */ 98 | public static ExcelImportResult importExcelVerify(InputStream inputstream, 99 | Class pojoClass, ImportParams params) 100 | throws Exception { 101 | return new ExcelImportServer().importExcelByIs(inputstream, pojoClass, params); 102 | } 103 | 104 | /** 105 | * Excel 导入 数据源本地文件,返回校验结果 字段类型 Integer,Long,Double,Date,String,Boolean 106 | * 107 | * @param file 108 | * @param pojoClass 109 | * @param params 110 | * @return 111 | * @throws Exception 112 | */ 113 | public static ExcelImportResult importExcelVerify(File file, Class pojoClass, 114 | ImportParams params) { 115 | FileInputStream in = null; 116 | try { 117 | in = new FileInputStream(file); 118 | return new ExcelImportServer().importExcelByIs(in, pojoClass, params); 119 | } catch (Exception e) { 120 | LOGGER.error(e.getMessage(), e); 121 | } finally { 122 | try { 123 | in.close(); 124 | } catch (IOException e) { 125 | LOGGER.error(e.getMessage(), e); 126 | } 127 | } 128 | return null; 129 | } 130 | 131 | /** 132 | * Excel 通过SAX解析方法,适合大数据导入,不支持图片 133 | * 导入 数据源IO流,不返回校验结果 导入 字段类型 Integer,Long,Double,Date,String,Boolean 134 | * 135 | * @param inputstream 136 | * @param pojoClass 137 | * @param params 138 | * @return 139 | * @throws Exception 140 | */ 141 | public static List importExcelBySax(InputStream inputstream, Class pojoClass, 142 | ImportParams params) { 143 | return new SaxReadExcel().readExcel(inputstream, pojoClass, params, null, null); 144 | } 145 | 146 | /** 147 | * Excel 通过SAX解析方法,适合大数据导入,不支持图片 148 | * 导入 数据源本地文件,不返回校验结果 导入 字 段类型 Integer,Long,Double,Date,String,Boolean 149 | * 150 | * @param file 151 | * @param rowRead 152 | * @return 153 | * @throws Exception 154 | */ 155 | @SuppressWarnings("rawtypes") 156 | public static void importExcelBySax(InputStream inputstream, Class pojoClass, 157 | ImportParams params, IExcelReadRowHanlder hanlder) { 158 | new SaxReadExcel().readExcel(inputstream, pojoClass, params, null, hanlder); 159 | } 160 | 161 | /** 162 | * Excel 通过SAX解析方法,适合大数据导入,不支持图片 163 | * 导入 数据源IO流,不返回校验结果 导入 字段类型 Integer,Long,Double,Date,String,Boolean 164 | * 165 | * @param file 166 | * @param rowRead 167 | * @return 168 | * @throws Exception 169 | */ 170 | public static List importExcelBySax(InputStream inputstream, ISaxRowRead rowRead) { 171 | return new SaxReadExcel().readExcel(inputstream, null, null, rowRead, null); 172 | } 173 | 174 | } 175 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/org/jeecgframework/poi/excel/html/ExcelToHtmlServer.java: -------------------------------------------------------------------------------- 1 | package org.jeecgframework.poi.excel.html; 2 | 3 | import java.util.Formatter; 4 | import java.util.Iterator; 5 | 6 | import org.apache.poi.ss.usermodel.Cell; 7 | import org.apache.poi.ss.usermodel.CellStyle; 8 | import org.apache.poi.ss.usermodel.Row; 9 | import org.apache.poi.ss.usermodel.Sheet; 10 | import org.apache.poi.ss.usermodel.Workbook; 11 | import org.jeecgframework.poi.excel.html.helper.CellValueHelper; 12 | import org.jeecgframework.poi.excel.html.helper.MergedRegionHelper; 13 | import org.jeecgframework.poi.excel.html.helper.StylerHelper; 14 | 15 | /** 16 | * Excel转换成Html 服务 17 | * @author JueYue 18 | * @date 2015年5月10日 上午11:41:15 19 | */ 20 | public class ExcelToHtmlServer { 21 | 22 | private Workbook wb; 23 | private int sheetNum; 24 | private int cssRandom; 25 | 26 | /*是不是完成界面*/ 27 | private boolean completeHTML; 28 | private Formatter out; 29 | /*已经完成范围处理*/ 30 | private boolean gotBounds; 31 | private int firstColumn; 32 | private int endColumn; 33 | private static final String COL_HEAD_CLASS = "colHeader"; 34 | //private static final String ROW_HEAD_CLASS = "rowHeader"; 35 | 36 | private static final String DEFAULTS_CLASS = "excelDefaults"; 37 | 38 | public ExcelToHtmlServer(Workbook wb, boolean completeHTML, int sheetNum) { 39 | this.wb = wb; 40 | this.completeHTML = completeHTML; 41 | this.sheetNum = sheetNum; 42 | cssRandom = (int) Math.ceil(Math.random() * 1000); 43 | } 44 | 45 | public String printPage() { 46 | try { 47 | ensureOut(); 48 | if (completeHTML) { 49 | out.format("%n"); 50 | out.format("%n"); 51 | out.format("%n"); 52 | out.format("%n"); 53 | } 54 | new StylerHelper(wb, out, sheetNum, cssRandom); 55 | if (completeHTML) { 56 | out.format("%n"); 57 | out.format("%n"); 58 | } 59 | print(); 60 | if (completeHTML) { 61 | out.format("%n"); 62 | out.format("%n"); 63 | } 64 | return out.toString(); 65 | } finally { 66 | if (out != null) 67 | out.close(); 68 | } 69 | } 70 | 71 | private void print() { 72 | printSheets(); 73 | } 74 | 75 | private void ensureOut() { 76 | if (out == null) 77 | out = new Formatter(new StringBuilder()); 78 | } 79 | 80 | private void printSheets() { 81 | Sheet sheet = wb.getSheetAt(sheetNum); 82 | printSheet(sheet); 83 | } 84 | 85 | private void printSheet(Sheet sheet) { 86 | out.format("%n", DEFAULTS_CLASS, getTableWidth(sheet)); 87 | printCols(sheet); 88 | printSheetContent(sheet); 89 | out.format("
%n"); 90 | } 91 | 92 | private void printCols(Sheet sheet) { 93 | //out.format("%n"); 94 | ensureColumnBounds(sheet); 95 | for (int i = firstColumn; i < endColumn; i++) { 96 | out.format("%n", sheet.getColumnWidth(i) / 32); 97 | } 98 | } 99 | 100 | private int getTableWidth(Sheet sheet) { 101 | ensureColumnBounds(sheet); 102 | int width = 0; 103 | for (int i = firstColumn; i < endColumn; i++) { 104 | width = width + (sheet.getColumnWidth(i) / 32); 105 | } 106 | return width; 107 | } 108 | 109 | private void ensureColumnBounds(Sheet sheet) { 110 | if (gotBounds) 111 | return; 112 | 113 | Iterator iter = sheet.rowIterator(); 114 | firstColumn = (iter.hasNext() ? Integer.MAX_VALUE : 0); 115 | endColumn = 0; 116 | while (iter.hasNext()) { 117 | Row row = iter.next(); 118 | short firstCell = row.getFirstCellNum(); 119 | if (firstCell >= 0) { 120 | firstColumn = Math.min(firstColumn, firstCell); 121 | endColumn = Math.max(endColumn, row.getLastCellNum()); 122 | } 123 | } 124 | gotBounds = true; 125 | } 126 | 127 | @SuppressWarnings("unused") 128 | /**本来是用来生成 A,B 那个列名称的**/ 129 | private void printColumnHeads(Sheet sheet) { 130 | out.format("%n"); 131 | out.format(" %n", COL_HEAD_CLASS); 132 | out.format(" ◊%n", COL_HEAD_CLASS); 133 | StringBuilder colName = new StringBuilder(); 134 | for (int i = firstColumn; i < endColumn; i++) { 135 | colName.setLength(0); 136 | int cnum = i; 137 | do { 138 | colName.insert(0, (char) ('A' + cnum % 26)); 139 | cnum /= 26; 140 | } while (cnum > 0); 141 | out.format(" %s%n", COL_HEAD_CLASS, colName); 142 | } 143 | out.format(" %n"); 144 | out.format("%n"); 145 | } 146 | 147 | private void printSheetContent(Sheet sheet) { 148 | //printColumnHeads(sheet); 149 | MergedRegionHelper mergedRegionHelper = new MergedRegionHelper(sheet); 150 | CellValueHelper cellValueHelper = new CellValueHelper(wb, cssRandom); 151 | out.format("%n"); 152 | Iterator rows = sheet.rowIterator(); 153 | int rowIndex = 1; 154 | while (rows.hasNext()) { 155 | Row row = rows.next(); 156 | out.format(" %n", row.getHeight() / 15); 157 | //out.format(" %d%n", ROW_HEAD_CLASS, row.getRowNum() + 1); 158 | for (int i = firstColumn; i < endColumn; i++) { 159 | if (mergedRegionHelper.isNeedCreate(rowIndex, i)) { 160 | String content = " "; 161 | CellStyle style = null; 162 | if (i >= row.getFirstCellNum() && i < row.getLastCellNum()) { 163 | Cell cell = row.getCell(i); 164 | if (cell != null) { 165 | style = cell.getCellStyle(); 166 | content = cellValueHelper.getHtmlValue(cell); 167 | } 168 | } 169 | if (mergedRegionHelper.isMergedRegion(rowIndex, i)) { 170 | Integer[] rowAndColSpan = mergedRegionHelper.getRowAndColSpan(rowIndex, i); 171 | out.format(" %s%n", 172 | rowAndColSpan[0], rowAndColSpan[1], styleName(style), content); 173 | } else { 174 | out.format(" %s%n", styleName(style), content); 175 | } 176 | } 177 | 178 | } 179 | out.format(" %n"); 180 | rowIndex++; 181 | } 182 | out.format("%n"); 183 | } 184 | 185 | private String styleName(CellStyle style) { 186 | if (style == null) 187 | return ""; 188 | return String.format("style_%02x_%s font_%s_%s", style.getIndex(), cssRandom, 189 | style.getFontIndex(), cssRandom); 190 | } 191 | } 192 | --------------------------------------------------------------------------------