├── easypoi-annotation ├── .gitignore ├── .settings │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.core.resources.prefs │ └── org.eclipse.jdt.core.prefs ├── pom.xml ├── .project ├── .classpath └── src │ └── main │ └── java │ └── cn │ └── afterturn │ └── easypoi │ └── excel │ └── annotation │ ├── ExcelIgnore.java │ ├── ExcelTarget.java │ ├── ExcelEntity.java │ └── ExcelCollection.java ├── easypoi-base ├── .gitignore ├── .settings │ ├── org.eclipse.m2e.core.prefs │ ├── org.eclipse.core.resources.prefs │ └── org.eclipse.jdt.core.prefs ├── src │ └── main │ │ └── java │ │ └── cn │ │ └── afterturn │ │ └── easypoi │ │ ├── excel │ │ ├── imports │ │ │ ├── package-info.java │ │ │ └── sax │ │ │ │ └── parse │ │ │ │ └── ISaxRowRead.java │ │ ├── graph │ │ │ ├── package-info.java │ │ │ ├── constant │ │ │ │ ├── ExcelGraphType.java │ │ │ │ └── ExcelGraphElementType.java │ │ │ └── entity │ │ │ │ ├── ExcelGraph.java │ │ │ │ ├── ExcelTitleCell.java │ │ │ │ ├── ExcelGraphElement.java │ │ │ │ └── ExcelGraphDefined.java │ │ ├── entity │ │ │ ├── ExportExcelItem.java │ │ │ ├── TemplateSumEntity.java │ │ │ ├── vo │ │ │ │ ├── BaseEntityTypeConstants.java │ │ │ │ └── PoiBaseConstants.java │ │ │ ├── enmus │ │ │ │ ├── ExcelType.java │ │ │ │ ├── CellValueType.java │ │ │ │ └── ExcelStyleType.java │ │ │ ├── sax │ │ │ │ ├── SaxConstant.java │ │ │ │ └── SaxReadCellEntity.java │ │ │ ├── result │ │ │ │ ├── ExcelVerifyHandlerResult.java │ │ │ │ └── ExcelImportResult.java │ │ │ ├── ExcelBaseParams.java │ │ │ ├── params │ │ │ │ ├── ExcelCollectionParams.java │ │ │ │ ├── MergeEntity.java │ │ │ │ ├── ExcelImportEntity.java │ │ │ │ ├── ExcelForEachParams.java │ │ │ │ └── ExcelBaseEntity.java │ │ │ ├── ExcelToHtmlParams.java │ │ │ └── ImportParams.java │ │ ├── package-info.java │ │ ├── html │ │ │ ├── helper │ │ │ │ └── excelStyle.css │ │ │ ├── entity │ │ │ │ ├── ExcelCssConstant.java │ │ │ │ ├── style │ │ │ │ │ ├── CssStyleFontEnity.java │ │ │ │ │ └── CellStyleEntity.java │ │ │ │ └── HtmlCssConstant.java │ │ │ └── css │ │ │ │ ├── ICssConvertToHtml.java │ │ │ │ ├── ICssConvertToExcel.java │ │ │ │ └── impl │ │ │ │ ├── BackgroundCssConvertImpl.java │ │ │ │ ├── HeightCssConverImpl.java │ │ │ │ ├── AlignCssConvertImpl.java │ │ │ │ ├── WidthCssConverImpl.java │ │ │ │ └── TextCssConvertImpl.java │ │ ├── export │ │ │ └── styler │ │ │ │ ├── IExcelExportStyler.java │ │ │ │ ├── ExcelExportStylerDefaultImpl.java │ │ │ │ ├── AbstractExcelExportStyler.java │ │ │ │ ├── ExcelExportStylerBorderImpl.java │ │ │ │ └── ExcelExportStylerColorImpl.java │ │ └── ExcelXorHtmlUtil.java │ │ ├── handler │ │ ├── package-info.java │ │ ├── impl │ │ │ ├── package-info.java │ │ │ └── ExcelDataHandlerDefaultImpl.java │ │ └── inter │ │ │ ├── IExcelI18nHandler.java │ │ │ ├── IExcelDataModel.java │ │ │ ├── IExcelExportServer.java │ │ │ ├── IWriter.java │ │ │ ├── IExcelDictHandler.java │ │ │ ├── IReadHandler.java │ │ │ ├── IExcelModel.java │ │ │ ├── IExcelVerifyHandler.java │ │ │ └── IExcelDataHandler.java │ │ ├── cache │ │ ├── package-info.java │ │ ├── HtmlCache.java │ │ ├── manager │ │ │ ├── IFileLoader.java │ │ │ ├── POICacheManager.java │ │ │ └── FileLoaderImpl.java │ │ ├── WordCache.java │ │ └── ExcelCache.java │ │ ├── pdf │ │ ├── package-info.java │ │ ├── styler │ │ │ ├── IPdfExportStyler.java │ │ │ └── PdfExportStylerDefaultImpl.java │ │ ├── PdfExportUtil.java │ │ └── entity │ │ │ └── PdfExportParams.java │ │ ├── word │ │ ├── package-info.java │ │ ├── WordExportUtil.java │ │ └── entity │ │ │ └── params │ │ │ ├── ListParamEntity.java │ │ │ └── ExcelListEntity.java │ │ ├── util │ │ ├── WebFilenameUtils.java │ │ ├── PoiExcelGraphDataUtil.java │ │ ├── PoiValidationUtil.java │ │ └── PoiExcelTempUtil.java │ │ ├── exception │ │ ├── excel │ │ │ ├── enums │ │ │ │ ├── ExcelImportEnum.java │ │ │ │ └── ExcelExportEnum.java │ │ │ ├── ExcelExportException.java │ │ │ └── ExcelImportException.java │ │ └── word │ │ │ ├── enmus │ │ │ └── WordExportEnum.java │ │ │ └── WordExportException.java │ │ ├── csv │ │ ├── CsvImportUtil.java │ │ ├── CsvExportUtil.java │ │ └── entity │ │ │ └── CsvExportParams.java │ │ └── entity │ │ └── ImageEntity.java ├── .project ├── .classpath └── pom.xml ├── easypoi-web ├── .gitignore ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.m2e.core.prefs │ └── org.eclipse.jdt.core.prefs ├── src │ └── main │ │ └── java │ │ └── cn │ │ └── afterturn │ │ └── easypoi │ │ ├── entity │ │ └── vo │ │ │ ├── MapExcelGraphConstants.java │ │ │ ├── BasePOIConstants.java │ │ │ ├── PDFTemplateConstants.java │ │ │ ├── BigExcelConstants.java │ │ │ ├── NormalExcelConstants.java │ │ │ ├── MapExcelConstants.java │ │ │ ├── TemplateWordConstants.java │ │ │ └── TemplateExcelConstants.java │ │ └── view │ │ ├── MiniAbstractExcelView.java │ │ ├── EasypoiBigExcelExportView.java │ │ ├── EasypoiMapExcelView.java │ │ ├── EasypoiTemplateWordView.java │ │ ├── EasypoiTemplateExcelView.java │ │ ├── PoiBaseView.java │ │ ├── MapGraphExcelView.java │ │ ├── EasypoiPDFTemplateView.java │ │ └── EasypoiSingleExcelView.java ├── .project ├── .classpath └── pom.xml ├── install.bat ├── deploy.bat ├── .gitignore └── .project /easypoi-annotation/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /easypoi-base/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /build/ 3 | -------------------------------------------------------------------------------- /easypoi-web/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /build/ 3 | -------------------------------------------------------------------------------- /install.bat: -------------------------------------------------------------------------------- 1 | cmd /k mvn clean install -D skipTest -------------------------------------------------------------------------------- /deploy.bat: -------------------------------------------------------------------------------- 1 | cmd /k mvn clean deploy -Dmaven.test.skip=true -------------------------------------------------------------------------------- /easypoi-web/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Package Files # 2 | .project 3 | .classpath 4 | .settings/ 5 | target/ 6 | deploy.bat 7 | 8 | /pom_bak.xml 9 | /deploy_sing.bat 10 | /build/ 11 | /bin/ 12 | .idea/ 13 | *.iml 14 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/imports/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 导入类 3 | * @author JueYue 4 | * 2014年6月23日 下午11:05:59 5 | */ 6 | package cn.afterturn.easypoi.excel.imports; -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/handler/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 数据处理中心,对导入导出进行数据处理 3 | * @author JueYue 4 | * 2014年6月20日 上午12:08:09 5 | */ 6 | package cn.afterturn.easypoi.handler; -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/handler/impl/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 对接口的抽象的默认实现,避免用户实现过多方法 3 | * @author JueYue 4 | * 2014年6月20日 上午12:09:27 5 | */ 6 | package cn.afterturn.easypoi.handler.impl; -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | /** 5 | * @author xfworld 6 | * @since 2016-1-13 7 | * @version 1.0 8 | * Excel 图形构造服务 9 | */ 10 | package cn.afterturn.easypoi.excel.graph; -------------------------------------------------------------------------------- /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/cn/afterturn/easypoi/cache/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 对POI用到的模板进行缓存,进行统一管理,缓存工具暂时使用guava(脱离配置文件) 3 | * 缓存方式统一为byte[] 屏蔽文件类型的差异 4 | * 缓存获取方式,URL或者URL+index(EXcel的) 5 | */ 6 | /** 7 | * @author JueYue 8 | * 2014年2月10日 9 | * @version 1.0 10 | */ 11 | package cn.afterturn.easypoi.cache; -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/constant/ExcelGraphType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package cn.afterturn.easypoi.excel.graph.constant; 5 | 6 | /** 7 | * @author xfworld 8 | * @since 2015-12-30 9 | * @version 1.0 10 | * 定义图形类型 11 | */ 12 | public interface ExcelGraphType 13 | { 14 | public static final Integer LINE_CHART =1; 15 | public static final Integer SCATTER_CHART =2; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/handler/inter/IExcelI18nHandler.java: -------------------------------------------------------------------------------- 1 | package cn.afterturn.easypoi.handler.inter; 2 | 3 | /** 4 | * @author jueyue on 18-2-2. 5 | * @version 3.0.4 6 | */ 7 | public interface IExcelI18nHandler { 8 | 9 | /** 10 | * 获取当前名称 11 | * 12 | * @param name 注解配置的 13 | * @return 返回国际化的名字 14 | */ 15 | public String getLocaleName(String name); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/constant/ExcelGraphElementType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package cn.afterturn.easypoi.excel.graph.constant; 5 | 6 | /** 7 | * @author xfworld 8 | * @since 2015-12-30 9 | * @version 1.0 10 | * 定义元素类型 11 | */ 12 | public interface ExcelGraphElementType 13 | { 14 | public static final Integer STRING_TYPE =1; 15 | public static final Integer NUMERIC_TYPE =2; 16 | } 17 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/handler/inter/IExcelDataModel.java: -------------------------------------------------------------------------------- 1 | package cn.afterturn.easypoi.handler.inter; 2 | 3 | /** 4 | * Excel 本身数据文件 5 | * @author by jueyue on 18-4-8. 6 | */ 7 | public interface IExcelDataModel { 8 | 9 | /** 10 | * 获取行号 11 | * @return 12 | */ 13 | public Integer getRowNum(); 14 | 15 | /** 16 | * 设置行号 17 | * @param rowNum 18 | */ 19 | public void setRowNum(Integer rowNum); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/cn/afterturn/easypoi/entity/vo/MapExcelGraphConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package cn.afterturn.easypoi.entity.vo; 5 | 6 | 7 | 8 | /** 9 | * @author xfworld 10 | * @since 2015-12-31 11 | * @version 1.0 12 | * 13 | */ 14 | public interface MapExcelGraphConstants extends MapExcelConstants 15 | { 16 | public final static String MAP_GRAPH_EXCEL_VIEW = "MapGraphExcelView"; 17 | public final static String GRAPH_DEFINED = "graphDefined"; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /easypoi-annotation/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | cn.afterturn 6 | easypoi 7 | 4.1.3 8 | 9 | easypoi-annotation 10 | base annotation 11 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/handler/inter/IExcelExportServer.java: -------------------------------------------------------------------------------- 1 | package cn.afterturn.easypoi.handler.inter; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 导出数据接口 7 | * 8 | * @author JueYue 9 | * 2016年9月8日 10 | */ 11 | public interface IExcelExportServer { 12 | /** 13 | * 查询数据接口 14 | * 15 | * @param queryParams 查询条件 16 | * @param page 当前页数从1开始 17 | * @return 18 | */ 19 | public List selectListForExcelExport(Object queryParams, int page); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ExportExcelItem.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package cn.afterturn.easypoi.excel.entity; 5 | 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; 10 | import lombok.Data; 11 | 12 | /** 13 | * @author xfworld 14 | * @since 2016-5-26 15 | * @version 1.0 16 | */ 17 | @Data 18 | public class ExportExcelItem { 19 | private List entityList; 20 | private List> resultList; 21 | } 22 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/entity/ExcelGraph.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package cn.afterturn.easypoi.excel.graph.entity; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author xfworld 10 | * @since 2016-1-7 11 | * @version 1.0 12 | * @see com.dawnpro.core.export.excel.model.ExcelGraph 13 | * 14 | */ 15 | public interface ExcelGraph 16 | { 17 | public ExcelGraphElement getCategory(); 18 | public List getValueList(); 19 | public Integer getGraphType(); 20 | public List getTitleCell(); 21 | public List getTitle(); 22 | } 23 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/TemplateSumEntity.java: -------------------------------------------------------------------------------- 1 | package cn.afterturn.easypoi.excel.entity; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * 统计对象 7 | * 8 | * @author JueYue 9 | */ 10 | @Data 11 | public class TemplateSumEntity { 12 | 13 | /** 14 | * CELL的值 15 | */ 16 | private String cellValue; 17 | /** 18 | * 需要计算的KEY 19 | */ 20 | private String sumKey; 21 | /** 22 | * 列 23 | */ 24 | private int col; 25 | /** 26 | * 行 27 | */ 28 | private int row; 29 | /** 30 | * 最后值 31 | */ 32 | private double value; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/vo/BaseEntityTypeConstants.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package cn.afterturn.easypoi.excel.entity.vo; 5 | 6 | /** 7 | * @author xfworld 8 | * @since 2015-12-28 9 | * @version 1.0 10 | * @see cn.afterturn.easypoi.excel.entity.vo.BaseEntityTypeConstants 11 | * 12 | */ 13 | public interface BaseEntityTypeConstants { 14 | public final static Integer STRING_TYPE = 1; 15 | public final static Integer IMAGE_TYPE = 2; 16 | public final static Integer FUNCTION_TYPE = 3; 17 | public final static Integer DATE_TYPE = 4; 18 | public final static Integer DOUBLE_TYPE = 10; 19 | } 20 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/cache/HtmlCache.java: -------------------------------------------------------------------------------- 1 | package cn.afterturn.easypoi.cache; 2 | 3 | import cn.afterturn.easypoi.excel.entity.ExcelToHtmlParams; 4 | import cn.afterturn.easypoi.excel.html.ExcelToHtmlService; 5 | 6 | /** 7 | * Excel 转变成为Html 的缓存 8 | * 9 | * @author JueYue 10 | * 2015年8月7日 下午1:29:47 11 | */ 12 | public class HtmlCache { 13 | 14 | public static String getHtml(ExcelToHtmlParams params) { 15 | try { 16 | return new ExcelToHtmlService(params).printPage(); 17 | } catch (Exception e) { 18 | throw new RuntimeException(e); 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/handler/inter/IWriter.java: -------------------------------------------------------------------------------- 1 | package cn.afterturn.easypoi.handler.inter; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 大数据写出服务接口 7 | * 8 | * @author jueyue on 19-11-25. 9 | */ 10 | public interface IWriter { 11 | /** 12 | * 获取输出对象 13 | * 14 | * @return 15 | */ 16 | default public T get() { 17 | return null; 18 | } 19 | 20 | /** 21 | * 写入数据 22 | * 23 | * @param data 24 | * @return 25 | */ 26 | public IWriter write(Collection data); 27 | 28 | /** 29 | * 关闭流,完成业务 30 | * 31 | * @return 32 | */ 33 | public T close(); 34 | } 35 | -------------------------------------------------------------------------------- /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.m2e.core.maven2Nature 21 | org.springsource.ide.eclipse.gradle.core.nature 22 | org.eclipse.jdt.core.javanature 23 | 24 | 25 | -------------------------------------------------------------------------------- /easypoi-base/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.6 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 12 | org.eclipse.jdt.core.compiler.source=1.6 13 | -------------------------------------------------------------------------------- /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.springsource.ide.eclipse.gradle.core.nature 21 | org.eclipse.jdt.core.javanature 22 | org.eclipse.m2e.core.maven2Nature 23 | 24 | 25 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/entity/ExcelTitleCell.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package cn.afterturn.easypoi.excel.graph.entity; 5 | 6 | /** 7 | * @author xfowrld 8 | * @since 2015-12-30 9 | * @version 1.0 10 | * 11 | */ 12 | public class ExcelTitleCell 13 | { 14 | private Integer row; 15 | private Integer col; 16 | 17 | public ExcelTitleCell(){ 18 | 19 | } 20 | 21 | public ExcelTitleCell(Integer row,Integer col){ 22 | this.row=row; 23 | this.col=col; 24 | } 25 | 26 | public Integer getRow() 27 | { 28 | return row; 29 | } 30 | public void setRow(Integer row) 31 | { 32 | this.row = row; 33 | } 34 | public Integer getCol() 35 | { 36 | return col; 37 | } 38 | public void setCol(Integer col) 39 | { 40 | this.col = col; 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/handler/inter/IExcelDictHandler.java: -------------------------------------------------------------------------------- 1 | package cn.afterturn.easypoi.handler.inter; 2 | 3 | /** 4 | * @author jueyue on 18-2-2. 5 | * @version 3.0.4 6 | */ 7 | public interface IExcelDictHandler { 8 | 9 | /** 10 | * 从值翻译到名称 11 | * 12 | * @param dict 字典Key 13 | * @param obj 对象 14 | * @param name 属性名称 15 | * @param value 属性值 16 | * @return 17 | */ 18 | public String toName(String dict, Object obj, String name, Object value); 19 | 20 | /** 21 | * 从名称翻译到值 22 | * 23 | * @param dict 字典Key 24 | * @param obj 对象 25 | * @param name 属性名称 26 | * @param value 属性值 27 | * @return 28 | */ 29 | public String toValue(String dict, Object obj, String name, Object value); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/pdf/package-info.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 | /** 17 | * EasyPOI的PDF模块 18 | * @author JueYue 19 | * 2015年10月6日 下午8:13:19 20 | */ 21 | package cn.afterturn.easypoi.pdf; -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/word/package-info.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 | /** 17 | * Word 模块,因为2003不好用,所以都是基于2007来处理的数据 18 | * @author JueYue 19 | * 2014年6月20日 上午12:08:09 20 | */ 21 | package cn.afterturn.easypoi.word; -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/package-info.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 | /** 17 | * Excel模块,支持2003,2007的导入导出,模板的导出,流的导出(大数据量) 18 | * @author JueYue 19 | * 2014年6月20日 上午12:08:09 20 | */ 21 | package cn.afterturn.easypoi.excel; -------------------------------------------------------------------------------- /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.springsource.ide.eclipse.gradle.core.nature 26 | org.eclipse.jdt.core.javanature 27 | org.springframework.ide.eclipse.core.springnature 28 | org.eclipse.m2e.core.maven2Nature 29 | 30 | 31 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.excel.entity.enmus; 17 | 18 | /** 19 | * Excel Type 20 | * @author JueYue 21 | * 2014年12月29日 下午9:08:21 22 | */ 23 | public enum ExcelType { 24 | 25 | HSSF , XSSF; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.excel.entity.enmus; 17 | 18 | /** 19 | * Cell 值得类型 20 | * @author JueYue 21 | * 2014年12月29日 下午10:20:49 22 | */ 23 | public enum CellValueType { 24 | 25 | InlineStr, String, Number, Boolean, Date, TElement, Null, Formula, None; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/cache/manager/IFileLoader.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 cn.afterturn.easypoi.cache.manager; 17 | 18 | /** 19 | * 缓存读取 20 | * @author JueYue 21 | * 默认实现是FileLoader 22 | * 2015年10月17日 下午7:12:01 23 | */ 24 | public interface IFileLoader { 25 | /** 26 | * 可以自定义KEY的作用 27 | * @param key 28 | * @return 29 | */ 30 | public byte[] getFile(String key); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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-base/src/main/java/cn/afterturn/easypoi/excel/html/entity/ExcelCssConstant.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2017 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 cn.afterturn.easypoi.excel.html.entity; 17 | 18 | /** 19 | * Excel 自定义处理的自定义Html标签 20 | * @author JueYue 21 | * 2017年3月26日 22 | */ 23 | public interface ExcelCssConstant { 24 | 25 | public final String SHEET_NAME = "sheetName"; 26 | public final String FREEZE_ROW = "freezeRow"; 27 | public final String FREEZE_COL = "freezeCol"; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/handler/inter/IReadHandler.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 cn.afterturn.easypoi.handler.inter; 17 | 18 | /** 19 | * 接口自定义处理类 20 | * @author JueYue 21 | * 2015年1月16日 下午8:06:26 22 | * @param 23 | */ 24 | public interface IReadHandler { 25 | /** 26 | * 处理解析对象 27 | * @param t 28 | */ 29 | public void handler(T t); 30 | 31 | 32 | /** 33 | * 处理完成之后的业务 34 | */ 35 | public void doAfterAll(); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/handler/inter/IExcelModel.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 cn.afterturn.easypoi.handler.inter; 17 | 18 | /** 19 | * Excel标记类 20 | * @author JueYue 21 | * 2015年10月31日 下午9:31:47 22 | */ 23 | public interface IExcelModel { 24 | 25 | /** 26 | * 获取错误数据 27 | * @return 28 | */ 29 | public String getErrorMsg(); 30 | 31 | /** 32 | * 设置错误信息 33 | * @param errorMsg 34 | */ 35 | public void setErrorMsg(String errorMsg); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /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 | 28 | -------------------------------------------------------------------------------- /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 | 28 | -------------------------------------------------------------------------------- /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 | 28 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.excel.imports.sax.parse; 17 | 18 | import java.util.List; 19 | 20 | import cn.afterturn.easypoi.excel.entity.sax.SaxReadCellEntity; 21 | 22 | /** 23 | * @author jueyue 24 | * @since 3.1 25 | * @date 2017-11-9 13:04:06 26 | */ 27 | public interface ISaxRowRead { 28 | /** 29 | * 解析数据 30 | * @param index 31 | * @param cellList 32 | */ 33 | void parse(int index, List cellList); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /easypoi-annotation/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.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 | * 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/cn/afterturn/easypoi/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 cn.afterturn.easypoi.entity.vo; 17 | 18 | /** 19 | * 基础POI常量 20 | * @author JueYue 21 | * 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/cn/afterturn/easypoi/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 cn.afterturn.easypoi.handler.inter; 17 | 18 | import cn.afterturn.easypoi.excel.entity.result.ExcelVerifyHandlerResult; 19 | 20 | /** 21 | * 导入校验接口 22 | * 23 | * @author JueYue 24 | * 2014年6月23日 下午11:08:21 25 | */ 26 | public interface IExcelVerifyHandler { 27 | 28 | /** 29 | * 导入校验方法 30 | * 31 | * @param obj 32 | * 当前对象 33 | * @return 34 | */ 35 | public ExcelVerifyHandlerResult verifyHandler(T obj); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/cn/afterturn/easypoi/entity/vo/PDFTemplateConstants.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 cn.afterturn.easypoi.entity.vo; 17 | 18 | public interface PDFTemplateConstants extends BasePOIConstants { 19 | 20 | /** 21 | * PDF 22 | */ 23 | public final static String EASYPOI_PDF_TEMPLATE_VIEW = "easypoiPdfTemplateView"; 24 | /** 25 | * Entity List 26 | */ 27 | public final static String ENTITY_LIST = "EntityList"; 28 | /** 29 | * 数据列表 30 | */ 31 | public final static String DATA_LIST = "dataList"; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/util/WebFilenameUtils.java: -------------------------------------------------------------------------------- 1 | package cn.afterturn.easypoi.util; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | 7 | import java.io.UnsupportedEncodingException; 8 | 9 | /**根据RFC 5987规范生成disposition值, 解决浏览器兼容以及中文乱码问题 10 | * @author halfdo 11 | * @date 6/25/2019 12 | */ 13 | public class WebFilenameUtils { 14 | 15 | private static final Logger LOGGER = LoggerFactory.getLogger(WebFilenameUtils.class); 16 | 17 | private static final String DISPOSITION_FORMAT = "attachment; filename=\"%s\"; filename*=utf-8''%s"; 18 | 19 | /** 20 | * 未编码文件名转Content-Disposition值 21 | * 22 | * @param filename 未编码的文件名(包含文件后缀) 23 | * @return Content-Disposition值 24 | */ 25 | public static String disposition(String filename) { 26 | String codedFilename = filename; 27 | try { 28 | if (StringUtils.isNotBlank(filename)) { 29 | codedFilename = java.net.URLEncoder.encode(filename, "UTF-8"); 30 | } 31 | } catch (UnsupportedEncodingException e) { 32 | LOGGER.error("不支持的编码:", e); 33 | } 34 | return String.format(DISPOSITION_FORMAT, codedFilename, codedFilename); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /easypoi-annotation/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.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 | } 38 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/cn/afterturn/easypoi/entity/vo/BigExcelConstants.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 cn.afterturn.easypoi.entity.vo; 17 | 18 | /** 19 | * 正常导出Excel 20 | * @author JueYue on 14-3-8. 21 | * 静态常量 22 | */ 23 | public interface BigExcelConstants extends BasePOIConstants { 24 | /** 25 | * 单Sheet导出 26 | */ 27 | public final static String EASYPOI_BIG_EXCEL_VIEW = "easypoiBigExcelView"; 28 | /** 29 | * 查询参数 30 | */ 31 | public final static String DATA_PARAMS = "dataParams"; 32 | /** 33 | * 查询函数 34 | */ 35 | public final static String DATA_INTER = "dataInter"; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.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 EASYPOI_EXCEL_VIEW = "easypoiExcelView"; 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/cn/afterturn/easypoi/excel/html/css/ICssConvertToHtml.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 cn.afterturn.easypoi.excel.html.css; 17 | 18 | import org.apache.poi.ss.usermodel.Cell; 19 | import org.apache.poi.ss.usermodel.CellStyle; 20 | 21 | import cn.afterturn.easypoi.excel.html.entity.style.CellStyleEntity; 22 | 23 | /** 24 | * CSS Cell Style 转换类 25 | * @author JueYue 26 | * 2016年3月20日 下午4:53:04 27 | */ 28 | public interface ICssConvertToHtml { 29 | /** 30 | * 把Excel单元格样式转换成HTML样式 31 | * @param cell 32 | * 33 | */ 34 | public String convertToHtml(Cell cell, CellStyle cellStyle, CellStyleEntity style); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.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 EASYPOI_MAP_EXCEL_VIEW = "easypoiMapExcelView"; 28 | /** 29 | * Entity List 30 | */ 31 | public final static String ENTITY_LIST = "EntityList"; 32 | /** 33 | * 数据列表 34 | */ 35 | public final static String MAP_LIST = "mapList"; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.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-base/src/main/java/cn/afterturn/easypoi/excel/html/css/ICssConvertToExcel.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 cn.afterturn.easypoi.excel.html.css; 17 | 18 | import org.apache.poi.ss.usermodel.Cell; 19 | import org.apache.poi.ss.usermodel.CellStyle; 20 | 21 | import cn.afterturn.easypoi.excel.html.entity.style.CellStyleEntity; 22 | 23 | /** 24 | * CSS Cell Style 转换类 25 | * @author JueYue 26 | * 2016年3月20日 下午4:53:04 27 | */ 28 | public interface ICssConvertToExcel { 29 | /** 30 | * 把HTML样式转换成Cell样式 31 | * @param cell 32 | * @param style 33 | */ 34 | public void convertToExcel(Cell cell, CellStyle cellStyle, CellStyleEntity style); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.entity.vo; 17 | 18 | /** 19 | * Word 导出模板常量 20 | * @author JueYue 21 | * 2014年7月24日 下午11:26:46 22 | */ 23 | public interface TemplateWordConstants extends BasePOIConstants { 24 | /** 25 | * 模板导出 26 | */ 27 | public final static String EASYPOI_TEMPLATE_WORD_VIEW = "easypoiTemplateWordView"; 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/cn/afterturn/easypoi/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 cn.afterturn.easypoi.entity.vo; 17 | 18 | /** 19 | * 模板Excel导出常量 20 | * @author JueYue 21 | * 2014年6月30日 下午9:26:52 22 | */ 23 | public interface TemplateExcelConstants extends BasePOIConstants { 24 | /** 25 | * 模板导出 26 | */ 27 | public final static String EASYPOI_TEMPLATE_EXCEL_VIEW = "easypoiTemplateExcelView"; 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/cn/afterturn/easypoi/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 cn.afterturn.easypoi.exception.excel.enums; 17 | 18 | /** 19 | * 导出异常类型枚举 20 | * @author JueYue 21 | * 2014年6月19日 下午10:59:51 22 | */ 23 | public enum ExcelImportEnum { 24 | PARAMETER_ERROR("参数错误"), 25 | IS_NOT_A_VALID_TEMPLATE("不是合法的Excel模板"), 26 | GET_VALUE_ERROR("Excel 值获取失败"), 27 | VERIFY_ERROR("值校验失败"); 28 | 29 | private String msg; 30 | 31 | ExcelImportEnum(String msg) { 32 | this.msg = msg; 33 | } 34 | 35 | public String getMsg() { 36 | return msg; 37 | } 38 | 39 | public void setMsg(String msg) { 40 | this.msg = msg; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.exception.word.enmus; 17 | 18 | /** 19 | * 导出异常枚举 20 | * 21 | * @author JueYue 22 | * 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/cn/afterturn/easypoi/excel/entity/sax/SaxConstant.java: -------------------------------------------------------------------------------- 1 | package cn.afterturn.easypoi.excel.entity.sax; 2 | 3 | /** 4 | * @author by jueyue on 19-6-20. 5 | */ 6 | public interface SaxConstant { 7 | 8 | /** 9 | * Row 表达式 10 | */ 11 | public static String ROW = "row"; 12 | /** 13 | * cell 的位置 14 | */ 15 | public static String ROW_COL = "r"; 16 | /** 17 | * cell 表达式 18 | */ 19 | public static String COL = "c"; 20 | /** 21 | * tElement 表达式 22 | */ 23 | public static String T_ELEMENT = "t"; 24 | /** 25 | * cell 类型 26 | */ 27 | public static String TYPE = "t"; 28 | /** 29 | * style 缩写 30 | */ 31 | public static String STYLE = "s"; 32 | /** 33 | * String 缩写 34 | */ 35 | public static String STRING = "s"; 36 | /** 37 | * date 缩写 38 | */ 39 | public static String DATE = "d"; 40 | /** 41 | * number 缩写 42 | */ 43 | public static String NUMBER = "n"; 44 | /** 45 | * 计算表达式 46 | */ 47 | public static String FORMULA = "str"; 48 | /** 49 | * Boolean 缩写 50 | */ 51 | public static String BOOLEAN = "b"; 52 | /** 53 | * 类型值为“inlineStr”,表示这个单元格的字符串并没有用共享字符串池子的值 54 | */ 55 | public static String INLINE_STR = "inlineStr"; 56 | 57 | 58 | /** 59 | * value 缩写 60 | */ 61 | public static String VALUE = "v"; 62 | 63 | } 64 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.exception.word; 17 | 18 | import cn.afterturn.easypoi.exception.word.enmus.WordExportEnum; 19 | 20 | /** 21 | * word导出异常 22 | * 23 | * @author JueYue 24 | * 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-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.exception.excel.enums; 17 | 18 | /** 19 | * 导出异常类型枚举 20 | * @author JueYue 21 | * 2014年6月19日 下午10:59:51 22 | */ 23 | public enum ExcelExportEnum { 24 | 25 | PARAMETER_ERROR ("Excel 导出 参数错误") , 26 | EXPORT_ERROR ("Excel导出错误") , 27 | HTML_ERROR ("Excel导出Html流错误") , 28 | TEMPLATE_ERROR ("Excel 模板错误"); 29 | 30 | private String msg; 31 | 32 | ExcelExportEnum(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 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | easypoi 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.m2e.core.maven2Nature 21 | org.eclipse.jdt.core.javanature 22 | 23 | 24 | 25 | 1464242916850 26 | 27 | 26 28 | 29 | org.eclipse.ui.ide.orFilterMatcher 30 | 31 | 32 | org.eclipse.ui.ide.multiFilter 33 | 1.0-projectRelativePath-equals-true-false-easypoi-annotation 34 | 35 | 36 | org.eclipse.ui.ide.multiFilter 37 | 1.0-projectRelativePath-equals-true-false-easypoi-base 38 | 39 | 40 | org.eclipse.ui.ide.multiFilter 41 | 1.0-projectRelativePath-equals-true-false-easypoi-web 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/result/ExcelVerifyHandlerResult.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 cn.afterturn.easypoi.excel.entity.result; 17 | 18 | import lombok.Data; 19 | 20 | /** 21 | * Excel导入处理返回结果 22 | * 23 | * @author JueYue 24 | * 2014年6月23日 下午11:03:29 25 | */ 26 | @Data 27 | public class ExcelVerifyHandlerResult { 28 | /** 29 | * 是否正确 30 | */ 31 | private boolean success; 32 | /** 33 | * 错误信息 34 | */ 35 | private String msg; 36 | 37 | public ExcelVerifyHandlerResult() { 38 | 39 | } 40 | 41 | public ExcelVerifyHandlerResult(boolean success) { 42 | this.success = success; 43 | } 44 | 45 | public ExcelVerifyHandlerResult(boolean success, String msg) { 46 | this.success = success; 47 | this.msg = msg; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/entity/ExcelGraphElement.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package cn.afterturn.easypoi.excel.graph.entity; 5 | 6 | import cn.afterturn.easypoi.excel.graph.constant.ExcelGraphElementType; 7 | 8 | 9 | /** 10 | * @author xfworld 11 | * @since 2015-12-30 12 | * @version 1.0 13 | * 14 | */ 15 | public class ExcelGraphElement 16 | { 17 | private Integer startRowNum; 18 | private Integer endRowNum; 19 | private Integer startColNum; 20 | private Integer endColNum; 21 | private Integer elementType=ExcelGraphElementType.STRING_TYPE; 22 | 23 | 24 | public Integer getStartRowNum() 25 | { 26 | return startRowNum; 27 | } 28 | public void setStartRowNum(Integer startRowNum) 29 | { 30 | this.startRowNum = startRowNum; 31 | } 32 | public Integer getEndRowNum() 33 | { 34 | return endRowNum; 35 | } 36 | public void setEndRowNum(Integer endRowNum) 37 | { 38 | this.endRowNum = endRowNum; 39 | } 40 | public Integer getStartColNum() 41 | { 42 | return startColNum; 43 | } 44 | public void setStartColNum(Integer startColNum) 45 | { 46 | this.startColNum = startColNum; 47 | } 48 | public Integer getEndColNum() 49 | { 50 | return endColNum; 51 | } 52 | public void setEndColNum(Integer endColNum) 53 | { 54 | this.endColNum = endColNum; 55 | } 56 | public Integer getElementType() 57 | { 58 | return elementType; 59 | } 60 | public void setElementType(Integer elementType) 61 | { 62 | this.elementType = elementType; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.excel.entity; 17 | 18 | import cn.afterturn.easypoi.handler.inter.IExcelDataHandler; 19 | import cn.afterturn.easypoi.handler.inter.IExcelDictHandler; 20 | import cn.afterturn.easypoi.handler.inter.IExcelI18nHandler; 21 | import lombok.Data; 22 | 23 | /** 24 | * 基础参数 25 | * @author JueYue 26 | * 2014年6月20日 下午1:56:52 27 | */ 28 | @Data 29 | public class ExcelBaseParams { 30 | 31 | /** 32 | * 数据处理接口,以此为主,replace,format都在这后面 33 | */ 34 | private IExcelDataHandler dataHandler; 35 | 36 | /** 37 | * 字段处理类 38 | */ 39 | private IExcelDictHandler dictHandler; 40 | /** 41 | * 国际化处理类 42 | */ 43 | private IExcelI18nHandler i18nHandler; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.excel.entity.params; 17 | 18 | import lombok.Data; 19 | 20 | import java.util.Map; 21 | 22 | /** 23 | * Excel 对于的 Collection 24 | * 25 | * @author JueYue 26 | * 2013-9-26 27 | * @version 1.0 28 | */ 29 | @Data 30 | public class ExcelCollectionParams { 31 | 32 | /** 33 | * 集合对应的名称 34 | */ 35 | private String name; 36 | /** 37 | * Excel 列名称 38 | */ 39 | private String excelName; 40 | /** 41 | * 实体对象 42 | */ 43 | private Class type; 44 | /** 45 | * 这个list下面的参数集合实体对象 46 | */ 47 | private Map excelParams; 48 | 49 | } 50 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/csv/CsvImportUtil.java: -------------------------------------------------------------------------------- 1 | package cn.afterturn.easypoi.csv; 2 | 3 | import cn.afterturn.easypoi.csv.entity.CsvImportParams; 4 | import cn.afterturn.easypoi.csv.imports.CsvImportService; 5 | import cn.afterturn.easypoi.handler.inter.IReadHandler; 6 | 7 | import java.io.InputStream; 8 | import java.util.List; 9 | 10 | /** 11 | * CSV 导入工具类 12 | * 具体和Excel类似,但是比Excel简单 13 | * 需要处理一些字符串的处理 14 | * 15 | * @author by jueyue on 18-10-3. 16 | */ 17 | public final class CsvImportUtil { 18 | 19 | /** 20 | * Csv 导入流适合大数据导入 21 | * 导入 数据源IO流,不返回校验结果 导入 字段类型 Integer,Long,Double,Date,String,Boolean 22 | * 23 | * @param inputstream 24 | * @param pojoClass 25 | * @param params 26 | * @return 27 | */ 28 | public static List importCsv(InputStream inputstream, Class pojoClass, 29 | CsvImportParams params) { 30 | return new CsvImportService().readExcel(inputstream, pojoClass, params, null); 31 | } 32 | 33 | /** 34 | * Csv 导入流适合大数据导入 35 | * 导入 数据源IO流,不返回校验结果 导入 字段类型 Integer,Long,Double,Date,String,Boolean 36 | * 37 | * @param inputstream 38 | * @param pojoClass 39 | * @param params 40 | * @return 41 | */ 42 | public static void importCsv(InputStream inputstream, Class pojoClass, 43 | CsvImportParams params, IReadHandler readHandler) { 44 | new CsvImportService().readExcel(inputstream, pojoClass, params, readHandler); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.excel.entity.sax; 17 | 18 | import cn.afterturn.easypoi.excel.entity.enmus.CellValueType; 19 | import lombok.Data; 20 | 21 | /** 22 | * Cell 对象 23 | * @author JueYue 24 | * 2014年12月29日 下午10:12:57 25 | */ 26 | @Data 27 | public class SaxReadCellEntity { 28 | /** 29 | * 值类型 30 | */ 31 | private CellValueType cellType; 32 | /** 33 | * 值 34 | */ 35 | private Object value; 36 | 37 | public SaxReadCellEntity(CellValueType cellType, Object value) { 38 | this.cellType = cellType; 39 | this.value = value; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "[type=" + cellType.toString() + ",value=" + value + "]"; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.excel.entity.params; 17 | 18 | import lombok.Data; 19 | 20 | import java.util.List; 21 | 22 | /** 23 | * 合并单元格使用对象 24 | * 25 | * Created by jue on 14-6-11. 26 | */ 27 | @Data 28 | public class MergeEntity { 29 | /** 30 | * 合并开始行 31 | */ 32 | private int startRow; 33 | /** 34 | * 合并结束行 35 | */ 36 | private int endRow; 37 | /** 38 | * 文字 39 | */ 40 | private String text; 41 | /** 42 | * 依赖关系文本 43 | */ 44 | private List relyList; 45 | 46 | public MergeEntity() { 47 | 48 | } 49 | 50 | public MergeEntity(String text, int startRow, int endRow) { 51 | this.text = text; 52 | this.endRow = endRow; 53 | this.startRow = startRow; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/pdf/styler/IPdfExportStyler.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 cn.afterturn.easypoi.pdf.styler; 17 | 18 | import com.itextpdf.text.Document; 19 | import com.itextpdf.text.Font; 20 | import com.itextpdf.text.pdf.PdfPCell; 21 | 22 | import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; 23 | 24 | /** 25 | * PDF导出样式设置 26 | * @author JueYue 27 | * 2016年1月7日 下午11:16:51 28 | */ 29 | public interface IPdfExportStyler { 30 | 31 | /** 32 | * 获取文档格式 33 | * @return 34 | */ 35 | public Document getDocument(); 36 | 37 | /** 38 | * 设置Cell的样式 39 | * @param entity 40 | * @param text 41 | */ 42 | public void setCellStyler(PdfPCell iCell, ExcelExportEntity entity, String text); 43 | 44 | /** 45 | * 获取字体 46 | * @param entity 47 | * @param text 48 | */ 49 | public Font getFont(ExcelExportEntity entity, String text); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /easypoi-annotation/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.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 | * 27 | */ 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Target(ElementType.FIELD) 30 | public @interface ExcelEntity { 31 | 32 | /** 33 | * 定义excel导出ID 来限定导出字段,处理一个类对应多个不同名称的情况 34 | */ 35 | public String id() default ""; 36 | 37 | /** 38 | * 导出时,对应数据库的字段 主要是用户区分每个字段, 不能有annocation重名的 导出时的列名 39 | * 导出排序跟定义了annotation的字段的顺序有关 可以使用a_id,b_id来确实是否使用 40 | */ 41 | public String name() default ""; 42 | 43 | /** 44 | * 如果等于true,name必须有值, Excel的表头会变成两行,同时改Excel内部数据不参与总排序,排序用下面这个来代替,内部再排序 45 | * 排序取当中最小值排序 46 | * @return 47 | */ 48 | public boolean show() default false; 49 | 50 | } 51 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/graph/entity/ExcelGraphDefined.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package cn.afterturn.easypoi.excel.graph.entity; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import cn.afterturn.easypoi.excel.graph.constant.ExcelGraphType; 10 | 11 | /** 12 | * @author xfworld 13 | * @since 2015-12-30 14 | * @version 1.0 15 | * 16 | */ 17 | public class ExcelGraphDefined implements ExcelGraph 18 | { 19 | private ExcelGraphElement category; 20 | public List valueList= new ArrayList<>(); 21 | public List titleCell= new ArrayList<>(); 22 | private Integer graphType=ExcelGraphType.LINE_CHART; 23 | public List title= new ArrayList<>(); 24 | 25 | @Override 26 | public ExcelGraphElement getCategory() 27 | { 28 | return category; 29 | } 30 | public void setCategory(ExcelGraphElement category) 31 | { 32 | this.category = category; 33 | } 34 | @Override 35 | public List getValueList() 36 | { 37 | return valueList; 38 | } 39 | public void setValueList(List valueList) 40 | { 41 | this.valueList = valueList; 42 | } 43 | 44 | @Override 45 | public Integer getGraphType() 46 | { 47 | return graphType; 48 | } 49 | public void setGraphType(Integer graphType) 50 | { 51 | this.graphType = graphType; 52 | } 53 | @Override 54 | public List getTitleCell() 55 | { 56 | return titleCell; 57 | } 58 | public void setTitleCell(List titleCell) 59 | { 60 | this.titleCell = titleCell; 61 | } 62 | @Override 63 | public List getTitle() 64 | { 65 | return title; 66 | } 67 | public void setTitle(List title) 68 | { 69 | this.title = title; 70 | } 71 | 72 | 73 | 74 | } 75 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.excel.entity.enmus; 17 | 18 | import cn.afterturn.easypoi.excel.export.styler.ExcelExportStylerBorderImpl; 19 | import cn.afterturn.easypoi.excel.export.styler.ExcelExportStylerColorImpl; 20 | import cn.afterturn.easypoi.excel.export.styler.ExcelExportStylerDefaultImpl; 21 | 22 | /** 23 | * 插件提供的几个默认样式 24 | * @author JueYue 25 | * 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/cn/afterturn/easypoi/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 cn.afterturn.easypoi.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-web/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | cn.afterturn 6 | easypoi 7 | 4.1.3 8 | 9 | easypoi-web 10 | 11 | 12 | 13 | org.springframework 14 | spring-web 15 | compile 16 | 17 | 18 | org.springframework 19 | spring-webmvc 20 | compile 21 | 22 | 23 | org.springframework 24 | spring-context 25 | compile 26 | 27 | 28 | org.springframework 29 | spring-core 30 | compile 31 | 32 | 33 | org.springframework 34 | spring-beans 35 | compile 36 | 37 | 38 | 39 | javax.servlet 40 | servlet-api 41 | provided 42 | 43 | 44 | 45 | 46 | com.itextpdf 47 | itextpdf 48 | true 49 | 50 | 51 | 52 | cn.afterturn 53 | easypoi-base 54 | 55 | 56 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/css/impl/BackgroundCssConvertImpl.java: -------------------------------------------------------------------------------- 1 | package cn.afterturn.easypoi.excel.html.css.impl; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | import org.apache.poi.hssf.usermodel.HSSFCell; 5 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; 6 | import org.apache.poi.ss.usermodel.Cell; 7 | import org.apache.poi.ss.usermodel.CellStyle; 8 | import org.apache.poi.ss.usermodel.FillPatternType; 9 | import org.apache.poi.xssf.usermodel.XSSFCell; 10 | import org.apache.poi.xssf.usermodel.XSSFCellStyle; 11 | 12 | import cn.afterturn.easypoi.excel.html.css.ICssConvertToExcel; 13 | import cn.afterturn.easypoi.excel.html.css.ICssConvertToHtml; 14 | import cn.afterturn.easypoi.excel.html.entity.style.CellStyleEntity; 15 | import cn.afterturn.easypoi.util.PoiCssUtils; 16 | 17 | public class BackgroundCssConvertImpl implements ICssConvertToExcel, ICssConvertToHtml { 18 | 19 | @Override 20 | public String convertToHtml(Cell cell, CellStyle cellStyle, CellStyleEntity style) { 21 | 22 | return null; 23 | } 24 | 25 | @Override 26 | public void convertToExcel(Cell cell, CellStyle cellStyle, CellStyleEntity style) { 27 | if (StringUtils.isEmpty(style.getBackground())) { 28 | return; 29 | } 30 | cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); // 填充图案 31 | if (cell instanceof XSSFCell) { 32 | ((XSSFCellStyle) cellStyle) 33 | .setFillForegroundColor(PoiCssUtils.parseColor(style.getBackground())); 34 | } else if (cell instanceof HSSFCell) { 35 | cellStyle.setFillForegroundColor( 36 | PoiCssUtils.parseColor((HSSFWorkbook) cell.getRow().getSheet().getWorkbook(), 37 | style.getBackground()).getIndex()); 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.cache; 17 | 18 | import java.io.InputStream; 19 | 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | 23 | import cn.afterturn.easypoi.cache.manager.POICacheManager; 24 | import cn.afterturn.easypoi.word.entity.MyXWPFDocument; 25 | 26 | /** 27 | * word 缓存中心 28 | * 29 | * @author JueYue 30 | * 2014年7月24日 下午10:54:31 31 | */ 32 | public class WordCache { 33 | 34 | private static final Logger LOGGER = LoggerFactory.getLogger(WordCache.class); 35 | 36 | public static MyXWPFDocument getXWPFDocument(String url) { 37 | InputStream is = null; 38 | try { 39 | is = POICacheManager.getFile(url); 40 | MyXWPFDocument doc = new MyXWPFDocument(is); 41 | return doc; 42 | } catch (Exception e) { 43 | LOGGER.error(e.getMessage(), e); 44 | } finally { 45 | try { 46 | is.close(); 47 | } catch (Exception e) { 48 | LOGGER.error(e.getMessage(), e); 49 | } 50 | } 51 | return null; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.excel.entity.result; 17 | 18 | import java.util.List; 19 | import java.util.Map; 20 | 21 | import lombok.Data; 22 | import org.apache.poi.ss.usermodel.Workbook; 23 | 24 | /** 25 | * 导入返回类 26 | * 27 | * @author JueYue 28 | * 2014年6月29日 下午5:12:10 29 | */ 30 | @Data 31 | public class ExcelImportResult { 32 | 33 | /** 34 | * 结果集 35 | */ 36 | private List list; 37 | /** 38 | * 失败数据 39 | */ 40 | private List failList; 41 | 42 | /** 43 | * 是否存在校验失败 44 | */ 45 | private boolean verifyFail; 46 | 47 | /** 48 | * 数据源 49 | */ 50 | private Workbook workbook; 51 | /** 52 | * 失败的数据源 53 | */ 54 | private Workbook failWorkbook; 55 | 56 | private Map map; 57 | 58 | public ExcelImportResult() { 59 | 60 | } 61 | 62 | public ExcelImportResult(List list, boolean verifyFail, Workbook workbook) { 63 | this.list = list; 64 | this.verifyFail = verifyFail; 65 | this.workbook = workbook; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.excel.entity.params; 17 | 18 | import lombok.Data; 19 | 20 | import java.util.List; 21 | 22 | /** 23 | * excel 导入工具类,对cell类型做映射 24 | * @author JueYue 25 | * @version 1.0 2013年8月24日 26 | */ 27 | @Data 28 | public class ExcelImportEntity extends ExcelBaseEntity { 29 | 30 | public final static String IMG_SAVE_PATH = "/excel/upload/img"; 31 | /** 32 | * 对应 Collection NAME 33 | */ 34 | private String collectionName; 35 | /** 36 | * 保存图片的地址 37 | */ 38 | private String saveUrl; 39 | /** 40 | * 保存图片的类型,1是文件,2是数据库 41 | */ 42 | private int saveType; 43 | /** 44 | * 对应exportType 45 | */ 46 | private String classType; 47 | /** 48 | * 后缀 49 | */ 50 | private String suffix; 51 | /** 52 | * 导入校验字段 53 | */ 54 | private boolean importField; 55 | 56 | /** 57 | * 枚举导入静态方法 58 | */ 59 | private String enumImportMethod; 60 | 61 | private List list; 62 | 63 | } 64 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiExcelGraphDataUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package cn.afterturn.easypoi.util; 5 | 6 | import java.util.List; 7 | 8 | import org.apache.poi.ss.usermodel.Drawing; 9 | import org.apache.poi.ss.usermodel.Sheet; 10 | 11 | import cn.afterturn.easypoi.excel.graph.entity.ExcelGraph; 12 | import cn.afterturn.easypoi.excel.graph.entity.ExcelGraphElement; 13 | 14 | /** 15 | * @author xfworld 16 | * @since 2016-1-4 17 | * @version 1.0 18 | * 构建特殊数据结构 19 | */ 20 | public class PoiExcelGraphDataUtil { 21 | 22 | /** 23 | * 构建获取数据最后行数 并写入到定义对象中 24 | * @param dataSourceSheet 25 | * @param graph 26 | */ 27 | public static void buildGraphData(Sheet dataSourceSheet, ExcelGraph graph) { 28 | if (graph != null && graph.getCategory() != null && graph.getValueList() != null 29 | && graph.getValueList().size() > 0) { 30 | graph.getCategory().setEndRowNum(dataSourceSheet.getLastRowNum()); 31 | for (ExcelGraphElement e : graph.getValueList()) { 32 | if (e != null) { 33 | e.setEndRowNum(dataSourceSheet.getLastRowNum()); 34 | } 35 | } 36 | } 37 | } 38 | 39 | /** 40 | * 构建多个图形对象 41 | * @param dataSourceSheet 42 | * @param graphList 43 | */ 44 | public static void buildGraphData(Sheet dataSourceSheet, List graphList) { 45 | if (graphList != null && graphList.size() > 0) { 46 | for (ExcelGraph graph : graphList) { 47 | buildGraphData(dataSourceSheet, graph); 48 | } 49 | } 50 | } 51 | 52 | /** 53 | * 获取画布,没有就创建一个 54 | * @param sheet 55 | * @return 56 | */ 57 | public static Drawing getDrawingPatriarch(Sheet sheet){ 58 | if(sheet.getDrawingPatriarch() == null){ 59 | sheet.createDrawingPatriarch(); 60 | } 61 | return sheet.getDrawingPatriarch(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelForEachParams.java: -------------------------------------------------------------------------------- 1 | package cn.afterturn.easypoi.excel.entity.params; 2 | 3 | import lombok.Data; 4 | import org.apache.poi.ss.usermodel.CellStyle; 5 | 6 | import java.io.Serializable; 7 | import java.util.Stack; 8 | 9 | /** 10 | * 模板for each是的参数 11 | * 12 | * @author JueYue 13 | * 2015年4月29日 下午9:22:48 14 | */ 15 | @Data 16 | public class ExcelForEachParams implements Serializable { 17 | 18 | /** 19 | * 20 | */ 21 | private static final long serialVersionUID = 1L; 22 | /** 23 | * key 24 | */ 25 | private String name; 26 | /** 27 | * key 28 | */ 29 | private Stack tempName; 30 | /** 31 | * 模板的cellStyle 32 | */ 33 | private CellStyle cellStyle; 34 | /** 35 | * 行高 36 | */ 37 | private short height; 38 | /** 39 | * 常量值 40 | */ 41 | private String constValue; 42 | /** 43 | * 列合并 44 | */ 45 | private int colspan = 1; 46 | /** 47 | * 行合并 48 | */ 49 | private int rowspan = 1; 50 | /** 51 | * 行合并 52 | */ 53 | private boolean collectCell; 54 | 55 | private boolean needSum; 56 | 57 | public ExcelForEachParams() { 58 | 59 | } 60 | 61 | public ExcelForEachParams(String name, CellStyle cellStyle, short height) { 62 | this.name = name; 63 | this.cellStyle = cellStyle; 64 | this.height = height; 65 | } 66 | 67 | public ExcelForEachParams(String name, CellStyle cellStyle, short height, boolean needSum) { 68 | this.name = name; 69 | this.cellStyle = cellStyle; 70 | this.height = height; 71 | this.needSum = needSum; 72 | } 73 | 74 | 75 | } 76 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.exception.excel; 17 | 18 | import cn.afterturn.easypoi.exception.excel.enums.ExcelExportEnum; 19 | 20 | /** 21 | * 导出异常 22 | * 23 | * @author JueYue 24 | * 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/cn/afterturn/easypoi/excel/html/css/impl/HeightCssConverImpl.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 cn.afterturn.easypoi.excel.html.css.impl; 17 | 18 | import org.apache.commons.lang3.StringUtils; 19 | import org.apache.poi.ss.usermodel.Cell; 20 | import org.apache.poi.ss.usermodel.CellStyle; 21 | import org.apache.poi.ss.usermodel.Row; 22 | 23 | import cn.afterturn.easypoi.excel.html.css.ICssConvertToExcel; 24 | import cn.afterturn.easypoi.excel.html.css.ICssConvertToHtml; 25 | import cn.afterturn.easypoi.excel.html.entity.style.CellStyleEntity; 26 | import cn.afterturn.easypoi.util.PoiCssUtils; 27 | 28 | 29 | /** 30 | * 行高转换实现类 31 | * @author JueYue 32 | * 2016年4月3日 上午10:26:47 33 | */ 34 | public class HeightCssConverImpl implements ICssConvertToExcel, ICssConvertToHtml { 35 | 36 | @Override 37 | public String convertToHtml(Cell cell, CellStyle cellStyle, CellStyleEntity style) { 38 | 39 | return null; 40 | } 41 | 42 | @Override 43 | public void convertToExcel(Cell cell, CellStyle cellStyle, CellStyleEntity style) { 44 | if (StringUtils.isNoneBlank(style.getHeight())) { 45 | int height = Math.round(PoiCssUtils.getInt(style.getHeight()) * 255 / 12.75F); 46 | Row row = cell.getRow(); 47 | if (height > row.getHeight()) { 48 | row.setHeight((short) height); 49 | } 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.excel.export.styler; 17 | 18 | import org.apache.poi.ss.usermodel.Cell; 19 | import org.apache.poi.ss.usermodel.CellStyle; 20 | 21 | import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; 22 | import cn.afterturn.easypoi.excel.entity.params.ExcelForEachParams; 23 | import org.apache.poi.util.Removal; 24 | 25 | /** 26 | * Excel导出样式接口 27 | * 28 | * @author JueYue 2015年1月9日 下午5:32:30 29 | */ 30 | public interface IExcelExportStyler { 31 | 32 | /** 33 | * 列表头样式 34 | */ 35 | public CellStyle getHeaderStyle(short headerColor); 36 | 37 | /** 38 | * 标题样式 39 | */ 40 | public CellStyle getTitleStyle(short color); 41 | 42 | /** 43 | * 获取样式方法 44 | */ 45 | @Deprecated 46 | @Removal( 47 | version = "4.2" 48 | ) 49 | public CellStyle getStyles(boolean parity, ExcelExportEntity entity); 50 | 51 | /** 52 | * 获取样式方法 53 | * 54 | * @param dataRow 数据行 55 | * @param obj 对象 56 | * @param data 数据 57 | */ 58 | public CellStyle getStyles(Cell cell, int dataRow, ExcelExportEntity entity, Object obj, Object data); 59 | 60 | /** 61 | * 模板使用的样式设置 62 | */ 63 | public CellStyle getTemplateStyles(boolean isSingle, ExcelForEachParams excelForEachParams); 64 | 65 | } 66 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.exception.excel; 17 | 18 | import cn.afterturn.easypoi.exception.excel.enums.ExcelImportEnum; 19 | 20 | /** 21 | * 导入异常 22 | * @author JueYue 23 | * 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 ExcelImportException(String message, Throwable cause) { 54 | super(message, cause); 55 | } 56 | 57 | public ExcelImportEnum getType() { 58 | return type; 59 | } 60 | 61 | public void setType(ExcelImportEnum type) { 62 | this.type = type; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.excel.entity.params; 17 | 18 | import java.lang.reflect.Method; 19 | import java.util.List; 20 | 21 | import cn.afterturn.easypoi.excel.entity.vo.BaseEntityTypeConstants; 22 | import lombok.Data; 23 | 24 | /** 25 | * Excel 导入导出基础对象类 26 | * @author JueYue 27 | * 2014年6月20日 下午2:26:09 28 | */ 29 | @Data 30 | public class ExcelBaseEntity { 31 | /** 32 | * 对应name 33 | */ 34 | protected String name; 35 | /** 36 | * 对应groupName 37 | */ 38 | protected String groupName; 39 | /** 40 | * 对应type 41 | */ 42 | private int type = BaseEntityTypeConstants.STRING_TYPE; 43 | /** 44 | * 数据库格式 45 | */ 46 | private String databaseFormat; 47 | /** 48 | * 导出日期格式 49 | */ 50 | private String format; 51 | /** 52 | * 导出日期格式 53 | */ 54 | private String[] replace; 55 | /** 56 | * 字典名称 57 | */ 58 | private String dict; 59 | /** 60 | * set/get方法 61 | */ 62 | private Method method; 63 | /** 64 | * 这个是不是超链接,如果是需要实现接口返回对象 65 | */ 66 | private boolean hyperlink; 67 | /** 68 | * 固定的列 69 | */ 70 | private Integer fixedIndex; 71 | /** 72 | * 时区 73 | */ 74 | private String timezone; 75 | 76 | private List methods; 77 | 78 | } 79 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.handler.impl; 17 | 18 | import java.util.Map; 19 | 20 | import org.apache.poi.ss.usermodel.CreationHelper; 21 | import org.apache.poi.ss.usermodel.Hyperlink; 22 | 23 | import cn.afterturn.easypoi.handler.inter.IExcelDataHandler; 24 | 25 | /** 26 | * 数据处理默认实现,返回空 27 | * 28 | * @author JueYue 29 | * 2014年6月20日 上午12:11:52 30 | */ 31 | public abstract class ExcelDataHandlerDefaultImpl implements IExcelDataHandler { 32 | /** 33 | * 需要处理的字段 34 | */ 35 | private String[] needHandlerFields; 36 | 37 | @Override 38 | public Object exportHandler(T obj, String name, Object value) { 39 | return value; 40 | } 41 | 42 | @Override 43 | public String[] getNeedHandlerFields() { 44 | return needHandlerFields; 45 | } 46 | 47 | @Override 48 | public Object importHandler(T obj, String name, Object value) { 49 | return value; 50 | } 51 | 52 | @Override 53 | public void setNeedHandlerFields(String[] needHandlerFields) { 54 | this.needHandlerFields = needHandlerFields; 55 | } 56 | 57 | @Override 58 | public void setMapValue(Map map, String originKey, Object value) { 59 | map.put(originKey, value); 60 | } 61 | 62 | @Override 63 | public Hyperlink getHyperlink(CreationHelper creationHelper, T obj, String name, Object value) { 64 | return null; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/css/impl/AlignCssConvertImpl.java: -------------------------------------------------------------------------------- 1 | package cn.afterturn.easypoi.excel.html.css.impl; 2 | 3 | import org.apache.poi.ss.usermodel.Cell; 4 | import org.apache.poi.ss.usermodel.CellStyle; 5 | 6 | import cn.afterturn.easypoi.excel.html.css.ICssConvertToExcel; 7 | import cn.afterturn.easypoi.excel.html.css.ICssConvertToHtml; 8 | import cn.afterturn.easypoi.excel.html.entity.HtmlCssConstant; 9 | import cn.afterturn.easypoi.excel.html.entity.style.CellStyleEntity; 10 | import org.apache.poi.ss.usermodel.HorizontalAlignment; 11 | import org.apache.poi.ss.usermodel.VerticalAlignment; 12 | 13 | public class AlignCssConvertImpl implements ICssConvertToExcel, ICssConvertToHtml { 14 | 15 | @Override 16 | public String convertToHtml(Cell cell, CellStyle cellStyle, CellStyleEntity style) { 17 | 18 | return null; 19 | } 20 | 21 | @Override 22 | public void convertToExcel(Cell cell, CellStyle cellStyle, CellStyleEntity style) { 23 | // align 24 | if (HtmlCssConstant.RIGHT.equals(style.getAlign())) { 25 | cellStyle.setAlignment(HorizontalAlignment.RIGHT); 26 | } else if (HtmlCssConstant.CENTER.equals(style.getAlign())) { 27 | cellStyle.setAlignment(HorizontalAlignment.CENTER); 28 | } else if (HtmlCssConstant.LEFT.equals(style.getAlign())) { 29 | cellStyle.setAlignment(HorizontalAlignment.LEFT); 30 | } else if (HtmlCssConstant.JUSTIFY.equals(style.getAlign())) { 31 | cellStyle.setAlignment(HorizontalAlignment.JUSTIFY); 32 | } 33 | // vertical align 34 | if (HtmlCssConstant.TOP.equals(style.getVetical())) { 35 | cellStyle.setVerticalAlignment(VerticalAlignment.TOP); 36 | } else if (HtmlCssConstant.CENTER.equals(style.getVetical())) { 37 | cellStyle.setVerticalAlignment(VerticalAlignment.CENTER); 38 | } else if (HtmlCssConstant.BOTTOM.equals(style.getVetical())) { 39 | cellStyle.setVerticalAlignment(VerticalAlignment.BOTTOM); 40 | } else if (HtmlCssConstant.JUSTIFY.equals(style.getVetical())) { 41 | cellStyle.setVerticalAlignment(VerticalAlignment.JUSTIFY); 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.view; 17 | 18 | import cn.afterturn.easypoi.util.WebFilenameUtils; 19 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; 20 | import org.apache.poi.ss.usermodel.Workbook; 21 | 22 | import javax.servlet.ServletOutputStream; 23 | import javax.servlet.http.HttpServletRequest; 24 | import javax.servlet.http.HttpServletResponse; 25 | 26 | /** 27 | * 基础抽象Excel View 28 | * @author JueYue 29 | * 2015年2月28日 下午1:41:05 30 | */ 31 | public abstract class MiniAbstractExcelView extends PoiBaseView { 32 | 33 | private static final String CONTENT_TYPE = "text/html;application/vnd.ms-excel"; 34 | 35 | protected static final String HSSF = ".xls"; 36 | protected static final String XSSF = ".xlsx"; 37 | 38 | public MiniAbstractExcelView() { 39 | setContentType(CONTENT_TYPE); 40 | } 41 | 42 | 43 | public void out(Workbook workbook, String codedFileName, HttpServletRequest request, 44 | HttpServletResponse response) throws Exception { 45 | if (workbook instanceof HSSFWorkbook) { 46 | codedFileName += HSSF; 47 | } else { 48 | codedFileName += XSSF; 49 | } 50 | // 用工具类生成符合RFC 5987标准的文件名header, 去掉UA判断 51 | response.setHeader("content-disposition", WebFilenameUtils.disposition(codedFileName)); 52 | ServletOutputStream out = response.getOutputStream(); 53 | workbook.write(out); 54 | out.flush(); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.word; 17 | 18 | import java.util.List; 19 | import java.util.Map; 20 | 21 | import org.apache.poi.xwpf.usermodel.XWPFDocument; 22 | 23 | import cn.afterturn.easypoi.word.parse.ParseWord07; 24 | 25 | /** 26 | * Word使用模板导出工具类 27 | * 28 | * @author JueYue 29 | * 2013-11-16 30 | * @version 1.0 31 | */ 32 | public class WordExportUtil { 33 | 34 | private WordExportUtil() { 35 | 36 | } 37 | 38 | /** 39 | * 解析Word2007版本 40 | * 41 | * @param url 42 | * 模板地址 43 | * @param map 44 | * 解析数据源 45 | * @return 46 | */ 47 | public static XWPFDocument exportWord07(String url, Map map) throws Exception { 48 | return new ParseWord07().parseWord(url, map); 49 | } 50 | 51 | /** 52 | * 解析Word2007版本 53 | * 54 | * @param document 55 | * 模板 56 | * @param map 57 | * 解析数据源 58 | */ 59 | public static void exportWord07(XWPFDocument document, Map map) throws Exception { 60 | new ParseWord07().parseWord(document, map); 61 | } 62 | 63 | /** 64 | * 一个模板生成多页 65 | * @param url 66 | * @param list 67 | * @return 68 | * @throws Exception 69 | */ 70 | public static XWPFDocument exportWord07(String url, List> list) throws Exception { 71 | return new ParseWord07().parseWord(url, list); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/css/impl/WidthCssConverImpl.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 cn.afterturn.easypoi.excel.html.css.impl; 17 | 18 | import org.apache.commons.lang3.StringUtils; 19 | import org.apache.poi.ss.usermodel.Cell; 20 | import org.apache.poi.ss.usermodel.CellStyle; 21 | import org.apache.poi.ss.usermodel.Sheet; 22 | 23 | import cn.afterturn.easypoi.excel.html.css.ICssConvertToExcel; 24 | import cn.afterturn.easypoi.excel.html.css.ICssConvertToHtml; 25 | import cn.afterturn.easypoi.excel.html.entity.style.CellStyleEntity; 26 | import cn.afterturn.easypoi.util.PoiCssUtils; 27 | 28 | /** 29 | * 列宽转换实现类 30 | * @author JueYue 31 | * 2016年4月3日 上午10:26:47 32 | */ 33 | public class WidthCssConverImpl implements ICssConvertToExcel, ICssConvertToHtml { 34 | 35 | @Override 36 | public String convertToHtml(Cell cell, CellStyle cellStyle, CellStyleEntity style) { 37 | 38 | return null; 39 | } 40 | 41 | @Override 42 | public void convertToExcel(Cell cell, CellStyle cellStyle, CellStyleEntity style) { 43 | if (StringUtils.isNoneBlank(style.getWidth())) { 44 | int width = (int) Math.round(PoiCssUtils.getInt(style.getWidth()) * 2048 / 8.43F); 45 | Sheet sheet = cell.getSheet(); 46 | int colIndex = cell.getColumnIndex(); 47 | if (width > sheet.getColumnWidth(colIndex)) { 48 | if (width > 255 * 256) { 49 | width = 255 * 256; 50 | } 51 | sheet.setColumnWidth(colIndex, width); 52 | } 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.cache; 17 | 18 | import java.io.InputStream; 19 | import java.util.Arrays; 20 | import java.util.List; 21 | 22 | import org.apache.poi.ss.usermodel.Workbook; 23 | import org.apache.poi.ss.usermodel.WorkbookFactory; 24 | import org.slf4j.Logger; 25 | import org.slf4j.LoggerFactory; 26 | 27 | import cn.afterturn.easypoi.cache.manager.POICacheManager; 28 | 29 | /** 30 | * Excel类型的缓存 31 | * 32 | * @author JueYue 33 | * 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 (Exception e) { 56 | LOGGER.error(e.getMessage(), e); 57 | } finally { 58 | try { 59 | is.close(); 60 | } catch (Exception e) { 61 | LOGGER.error(e.getMessage(), e); 62 | } 63 | } 64 | return null; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/cn/afterturn/easypoi/view/EasypoiBigExcelExportView.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 cn.afterturn.easypoi.view; 17 | 18 | import cn.afterturn.easypoi.entity.vo.BigExcelConstants; 19 | import cn.afterturn.easypoi.excel.ExcelExportUtil; 20 | import cn.afterturn.easypoi.excel.entity.ExportParams; 21 | import cn.afterturn.easypoi.handler.inter.IExcelExportServer; 22 | import org.apache.poi.ss.usermodel.Workbook; 23 | import org.springframework.stereotype.Controller; 24 | 25 | import javax.servlet.http.HttpServletRequest; 26 | import javax.servlet.http.HttpServletResponse; 27 | import java.util.Map; 28 | 29 | /** 30 | * @author JueYue on 14-3-8. Excel 生成解析器,减少用户操作 31 | */ 32 | @Controller(BigExcelConstants.EASYPOI_BIG_EXCEL_VIEW) 33 | public class EasypoiBigExcelExportView extends MiniAbstractExcelView { 34 | 35 | public EasypoiBigExcelExportView() { 36 | super(); 37 | } 38 | 39 | @Override 40 | protected void renderMergedOutputModel(Map model, HttpServletRequest request, 41 | HttpServletResponse response) throws Exception { 42 | String codedFileName = "临时文件"; 43 | Workbook workbook = ExcelExportUtil.exportBigExcel( 44 | (ExportParams) model.get(BigExcelConstants.PARAMS), 45 | (Class) model.get(BigExcelConstants.CLASS), 46 | (IExcelExportServer) model.get(BigExcelConstants.DATA_INTER), 47 | model.get(BigExcelConstants.DATA_PARAMS)); 48 | if (model.containsKey(BigExcelConstants.FILE_NAME)) { 49 | codedFileName = (String) model.get(BigExcelConstants.FILE_NAME); 50 | } 51 | out(workbook, codedFileName, request, response); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.cache.manager; 17 | 18 | import java.io.ByteArrayInputStream; 19 | import java.io.InputStream; 20 | import java.util.Arrays; 21 | 22 | import org.slf4j.Logger; 23 | import org.slf4j.LoggerFactory; 24 | 25 | /** 26 | * 缓存管理 27 | * 28 | * @author JueYue 29 | * 2014年2月10日 30 | * 2015年10月17日 31 | * @version 1.1 32 | */ 33 | public final class POICacheManager { 34 | 35 | private static final Logger LOGGER = LoggerFactory 36 | .getLogger(POICacheManager.class); 37 | 38 | private static IFileLoader fileLoader = new FileLoaderImpl(); 39 | 40 | private static ThreadLocal LOCAL_FILE_LOADER = new ThreadLocal(); 41 | 42 | public static InputStream getFile(String id) { 43 | try { 44 | byte[] result; 45 | //复杂数据,防止操作原数据 46 | if (LOCAL_FILE_LOADER.get() != null) { 47 | result = LOCAL_FILE_LOADER.get().getFile(id); 48 | } 49 | result = fileLoader.getFile(id); 50 | result = Arrays.copyOf(result, result.length); 51 | return new ByteArrayInputStream(result); 52 | } catch (Exception e) { 53 | LOGGER.error(e.getMessage(), e); 54 | } 55 | return null; 56 | } 57 | 58 | public static void setFileLoader(IFileLoader fileLoader) { 59 | POICacheManager.fileLoader = fileLoader; 60 | } 61 | 62 | /** 63 | * 一次线程有效 64 | * @param fileLoader 65 | */ 66 | public static void setFileLoaderOnce(IFileLoader fileLoader) { 67 | if (fileLoader != null) { 68 | LOCAL_FILE_LOADER.set(fileLoader); 69 | } 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/pdf/PdfExportUtil.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 cn.afterturn.easypoi.pdf; 17 | 18 | import java.io.OutputStream; 19 | import java.util.Collection; 20 | import java.util.List; 21 | import java.util.Map; 22 | 23 | import com.itextpdf.text.Document; 24 | 25 | import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; 26 | import cn.afterturn.easypoi.pdf.entity.PdfExportParams; 27 | import cn.afterturn.easypoi.pdf.export.PdfExportServer; 28 | 29 | /** 30 | * PDF 导出工具类 31 | * 32 | * @author JueYue 33 | * 2015年10月6日 下午8:14:01 34 | * @version 1.0 35 | */ 36 | public class PdfExportUtil { 37 | 38 | /** 39 | * 根据注解导出数据 40 | * @param entity 41 | * 表格标题属性 42 | * @param pojoClass 43 | * PDF对象Class 44 | * @param dataSet 45 | * PDF对象数据List 46 | */ 47 | public static Document exportPdf(PdfExportParams entity, Class pojoClass, 48 | Collection dataSet, OutputStream outStream) { 49 | return new PdfExportServer(outStream, entity).createPdf(entity, pojoClass, dataSet); 50 | } 51 | 52 | /** 53 | * 根据Map创建对应的PDF 54 | * @param entity 55 | * 表格标题属性 56 | * @param entityList 57 | * PDF对象Class 58 | * @param dataSet 59 | * PDF对象数据List 60 | */ 61 | public static Document exportPdf(PdfExportParams entity, List entityList, 62 | Collection> dataSet, 63 | OutputStream outStream) { 64 | 65 | return new PdfExportServer(outStream, entity).createPdfByExportEntity(entity, entityList, 66 | dataSet); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/ExcelXorHtmlUtil.java: -------------------------------------------------------------------------------- 1 | package cn.afterturn.easypoi.excel; 2 | 3 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; 4 | import org.apache.poi.ss.usermodel.Workbook; 5 | import org.apache.poi.util.IOUtils; 6 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 7 | 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | 11 | import cn.afterturn.easypoi.cache.HtmlCache; 12 | import cn.afterturn.easypoi.excel.entity.ExcelToHtmlParams; 13 | import cn.afterturn.easypoi.excel.entity.enmus.ExcelType; 14 | import cn.afterturn.easypoi.excel.html.HtmlToExcelService; 15 | import cn.afterturn.easypoi.exception.excel.ExcelExportException; 16 | import cn.afterturn.easypoi.exception.excel.enums.ExcelExportEnum; 17 | 18 | /** 19 | * Excel 变成界面 20 | * @author JueYue 21 | * 2015年5月10日 上午11:51:48 22 | */ 23 | public class ExcelXorHtmlUtil { 24 | 25 | private ExcelXorHtmlUtil() { 26 | } 27 | 28 | /** 29 | * 转换成为Table 30 | * @param wb Excel 31 | * @return 32 | */ 33 | public static String toTableHtml(Workbook wb) { 34 | return HtmlCache.getHtml(new ExcelToHtmlParams(wb, false, 0, null)); 35 | } 36 | 37 | /** 38 | * 转换成为完整界面,显示图片 39 | * @param wb Excel 40 | * @return 41 | */ 42 | public static String toAllHtml(Workbook wb) { 43 | return HtmlCache.getHtml(new ExcelToHtmlParams(wb, true, 0, null)); 44 | } 45 | 46 | /** 47 | * 转换成为Table 48 | * @param params 49 | * @return 50 | */ 51 | public static String excelToHtml(ExcelToHtmlParams params) { 52 | return HtmlCache.getHtml(params); 53 | } 54 | 55 | /** 56 | * Html 读取Excel 57 | * @param html 58 | * @param type 59 | * @return 60 | */ 61 | public static Workbook htmlToExcel(String html, ExcelType type) { 62 | Workbook workbook = null; 63 | if (ExcelType.HSSF.equals(type)) { 64 | workbook = new HSSFWorkbook(); 65 | } else { 66 | workbook = new XSSFWorkbook(); 67 | } 68 | new HtmlToExcelService().createSheet(html, workbook); 69 | return workbook; 70 | } 71 | 72 | /** 73 | * Html 读取Excel 74 | * @param is 75 | * @param type 76 | * @return 77 | */ 78 | public static Workbook htmlToExcel(InputStream is, ExcelType type) { 79 | try { 80 | return htmlToExcel(new String(IOUtils.toByteArray(is)), type); 81 | } catch (IOException e) { 82 | throw new ExcelExportException(ExcelExportEnum.HTML_ERROR, e); 83 | } 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.word.entity.params; 17 | 18 | /** 19 | * Excel 对象导出结构 20 | * 21 | * @author JueYue 22 | * 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/cn/afterturn/easypoi/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 cn.afterturn.easypoi.handler.inter; 17 | 18 | import java.util.Map; 19 | 20 | import org.apache.poi.ss.usermodel.CreationHelper; 21 | import org.apache.poi.ss.usermodel.Hyperlink; 22 | 23 | /** 24 | * Excel 导入导出 数据处理接口 25 | * 26 | * @author JueYue 27 | * 2014年6月19日 下午11:59:45 28 | */ 29 | public interface IExcelDataHandler { 30 | 31 | /** 32 | * 导出处理方法 33 | * 34 | * @param obj 35 | * 当前对象 36 | * @param name 37 | * 当前字段名称 38 | * @param value 39 | * 当前值 40 | * @return 41 | */ 42 | public Object exportHandler(T obj, String name, Object value); 43 | 44 | /** 45 | * 获取需要处理的字段,导入和导出统一处理了, 减少书写的字段 46 | * 47 | * @return 48 | */ 49 | public String[] getNeedHandlerFields(); 50 | 51 | /** 52 | * 导入处理方法 当前对象,当前字段名称,当前值 53 | * 54 | * @param obj 55 | * 当前对象 56 | * @param name 57 | * 当前字段名称 58 | * @param value 59 | * 当前值 60 | * @return 61 | */ 62 | public Object importHandler(T obj, String name, Object value); 63 | 64 | /** 65 | * 设置需要处理的属性列表 66 | * @param fields 67 | */ 68 | public void setNeedHandlerFields(String[] fields); 69 | 70 | /** 71 | * 设置Map导入,自定义 put 72 | * @param map 73 | * @param originKey 74 | * @param value 75 | */ 76 | public void setMapValue(Map map, String originKey, Object value); 77 | 78 | /** 79 | * 获取这个字段的 Hyperlink ,07版本需要,03版本不需要 80 | * @param creationHelper 81 | * @param obj 82 | * @param name 83 | * @param value 84 | * @return 85 | */ 86 | public Hyperlink getHyperlink(CreationHelper creationHelper, T obj, String name, Object value); 87 | 88 | } 89 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/csv/CsvExportUtil.java: -------------------------------------------------------------------------------- 1 | package cn.afterturn.easypoi.csv; 2 | 3 | import cn.afterturn.easypoi.csv.entity.CsvExportParams; 4 | import cn.afterturn.easypoi.csv.export.CsvExportService; 5 | import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; 6 | import cn.afterturn.easypoi.handler.inter.IExcelExportServer; 7 | import cn.afterturn.easypoi.handler.inter.IWriter; 8 | 9 | import java.io.OutputStream; 10 | import java.util.Collection; 11 | import java.util.List; 12 | 13 | /** 14 | * Csv批量导出文件 15 | * 16 | * @author by jueyue on 18-11-14. 17 | */ 18 | public final class CsvExportUtil { 19 | 20 | private CsvExportUtil() { 21 | } 22 | 23 | 24 | /** 25 | * export csv all list 26 | * 27 | * @param params 28 | * @param pojoClass 29 | * @param dataSet 30 | * @param outputStream 31 | */ 32 | public static void exportCsv(CsvExportParams params, Class pojoClass, Collection dataSet, OutputStream outputStream) { 33 | IWriter writer = new CsvExportService(outputStream, params, pojoClass); 34 | writer.write(dataSet); 35 | writer.close(); 36 | } 37 | 38 | /** 39 | * export csv use server 40 | * 41 | * @param params 42 | * @param pojoClass 43 | * @param server 44 | * @param queryParams 45 | * @param outputStream 46 | */ 47 | public static void exportCsv(CsvExportParams params, Class pojoClass, IExcelExportServer server, Object queryParams, OutputStream outputStream) { 48 | IWriter writer = new CsvExportService(outputStream, params, pojoClass); 49 | int page = 1; 50 | Collection dataSet; 51 | while ((dataSet = server.selectListForExcelExport(queryParams, page)) != null && dataSet.size() > 0) { 52 | page++; 53 | writer.write(dataSet); 54 | } 55 | writer.close(); 56 | } 57 | 58 | /** 59 | * @param params 表格标题属性 60 | * @param pojoClass Excel对象Class 61 | */ 62 | public static IWriter exportCsv(CsvExportParams params, Class pojoClass, OutputStream outputStream) { 63 | CsvExportUtil ce = new CsvExportUtil(); 64 | return new CsvExportService(outputStream, params, pojoClass); 65 | } 66 | 67 | /** 68 | * 根据Map创建对应的Excel 69 | * 70 | * @param params 表格标题属性 71 | * @param entityList Map对象列表 72 | */ 73 | public static IWriter exportCsv(CsvExportParams params, List entityList, OutputStream outputStream) { 74 | return new CsvExportService(outputStream, params, entityList); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/cn/afterturn/easypoi/view/EasypoiMapExcelView.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 cn.afterturn.easypoi.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.springframework.stereotype.Controller; 29 | 30 | import cn.afterturn.easypoi.entity.vo.MapExcelConstants; 31 | import cn.afterturn.easypoi.excel.ExcelExportUtil; 32 | import cn.afterturn.easypoi.excel.entity.ExportParams; 33 | import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; 34 | 35 | /** 36 | * Map 对象接口 37 | * 38 | * @author JueYue 39 | * 2014年11月25日 下午3:26:32 40 | */ 41 | @SuppressWarnings("unchecked") 42 | @Controller(MapExcelConstants.EASYPOI_MAP_EXCEL_VIEW) 43 | public class EasypoiMapExcelView extends MiniAbstractExcelView { 44 | 45 | public EasypoiMapExcelView() { 46 | super(); 47 | } 48 | 49 | @Override 50 | protected void renderMergedOutputModel(Map model, HttpServletRequest request, 51 | HttpServletResponse response) throws Exception { 52 | String codedFileName = "临时文件"; 53 | Workbook workbook = ExcelExportUtil.exportExcel( 54 | (ExportParams) model.get(MapExcelConstants.PARAMS), 55 | (List) model.get(MapExcelConstants.ENTITY_LIST), 56 | (Collection>) model.get(MapExcelConstants.MAP_LIST)); 57 | if (model.containsKey(MapExcelConstants.FILE_NAME)) { 58 | codedFileName = (String) model.get(MapExcelConstants.FILE_NAME); 59 | } 60 | out(workbook, codedFileName, request, response); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/entity/style/CssStyleFontEnity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2017 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 cn.afterturn.easypoi.excel.html.entity.style; 17 | 18 | /** 19 | * 字体样式 20 | * @author JueYue 21 | * 2017年3月26日 22 | */ 23 | public class CssStyleFontEnity { 24 | /** 25 | * italic 浏览器会显示一个斜体的字体样式。 26 | */ 27 | private String style; 28 | /** 29 | * bold 定义粗体字符 30 | */ 31 | private String weight; 32 | /** 33 | * 仅支持**px获取不带px的数字大小 34 | */ 35 | private int size; 36 | private String family; 37 | private String decoration; 38 | private String color; 39 | 40 | public String getStyle() { 41 | return style; 42 | } 43 | 44 | public void setStyle(String style) { 45 | this.style = style; 46 | } 47 | 48 | public String getWeight() { 49 | return weight; 50 | } 51 | 52 | public void setWeight(String weight) { 53 | this.weight = weight; 54 | } 55 | 56 | public int getSize() { 57 | return size; 58 | } 59 | 60 | public void setSize(int size) { 61 | this.size = size; 62 | } 63 | 64 | public String getFamily() { 65 | return family; 66 | } 67 | 68 | public void setFamily(String family) { 69 | this.family = family; 70 | } 71 | 72 | public String getColor() { 73 | return color; 74 | } 75 | 76 | public void setColor(String color) { 77 | this.color = color; 78 | } 79 | 80 | public String getDecoration() { 81 | return decoration; 82 | } 83 | 84 | public void setDecoration(String decoration) { 85 | this.decoration = decoration; 86 | } 87 | 88 | @Override 89 | public String toString() { 90 | return new StringBuilder().append(style).append(decoration).append(color).append(family) 91 | .append(size).append(weight).toString(); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/csv/entity/CsvExportParams.java: -------------------------------------------------------------------------------- 1 | package cn.afterturn.easypoi.csv.entity; 2 | 3 | import cn.afterturn.easypoi.excel.entity.ExcelBaseParams; 4 | 5 | /** 6 | * CSV 导入参数 7 | * 8 | * @author by jueyue on 18-10-3. 9 | */ 10 | public class CsvExportParams extends ExcelBaseParams { 11 | 12 | public static final String UTF8 = "utf-8"; 13 | public static final String GBK = "gbk"; 14 | public static final String GB2312 = "gb2312"; 15 | 16 | private String encoding = UTF8; 17 | 18 | /** 19 | * 分隔符 20 | */ 21 | private String spiltMark = ","; 22 | 23 | /** 24 | * 字符串标识符 25 | */ 26 | private String textMark = "\""; 27 | 28 | /** 29 | * 表格标题行数,默认0 30 | */ 31 | private int titleRows = 0; 32 | 33 | /** 34 | * 表头行数,默认1 35 | */ 36 | private int headRows = 1; 37 | /** 38 | * 过滤的属性 39 | */ 40 | private String[] exclusions; 41 | 42 | /** 43 | * 是否创建表头 44 | */ 45 | private boolean isCreateHeadRows = true; 46 | 47 | public CsvExportParams() { 48 | 49 | } 50 | 51 | public CsvExportParams(String encoding) { 52 | this.encoding = encoding; 53 | } 54 | 55 | public String getEncoding() { 56 | return encoding; 57 | } 58 | 59 | public void setEncoding(String encoding) { 60 | this.encoding = encoding; 61 | } 62 | 63 | public String getSpiltMark() { 64 | return spiltMark; 65 | } 66 | 67 | public void setSpiltMark(String spiltMark) { 68 | this.spiltMark = spiltMark; 69 | } 70 | 71 | public String getTextMark() { 72 | return textMark; 73 | } 74 | 75 | public void setTextMark(String textMark) { 76 | this.textMark = textMark; 77 | } 78 | 79 | public int getTitleRows() { 80 | return titleRows; 81 | } 82 | 83 | public void setTitleRows(int titleRows) { 84 | this.titleRows = titleRows; 85 | } 86 | 87 | public int getHeadRows() { 88 | return headRows; 89 | } 90 | 91 | public void setHeadRows(int headRows) { 92 | this.headRows = headRows; 93 | } 94 | 95 | public String[] getExclusions() { 96 | return exclusions; 97 | } 98 | 99 | public void setExclusions(String[] exclusions) { 100 | this.exclusions = exclusions; 101 | } 102 | 103 | public boolean isCreateHeadRows() { 104 | return isCreateHeadRows; 105 | } 106 | 107 | public void setCreateHeadRows(boolean createHeadRows) { 108 | isCreateHeadRows = createHeadRows; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/pdf/styler/PdfExportStylerDefaultImpl.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 cn.afterturn.easypoi.pdf.styler; 17 | 18 | import java.io.IOException; 19 | 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | 23 | import com.itextpdf.text.Document; 24 | import com.itextpdf.text.DocumentException; 25 | import com.itextpdf.text.Element; 26 | import com.itextpdf.text.Font; 27 | import com.itextpdf.text.PageSize; 28 | import com.itextpdf.text.Font.FontFamily; 29 | import com.itextpdf.text.pdf.BaseFont; 30 | import com.itextpdf.text.pdf.PdfPCell; 31 | 32 | import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; 33 | 34 | /** 35 | * 默认的PDFstyler 实现 36 | * @author JueYue 37 | * 2016年1月8日 下午2:06:26 38 | */ 39 | public class PdfExportStylerDefaultImpl implements IPdfExportStyler { 40 | 41 | private static final Logger LOGGER = LoggerFactory.getLogger(PdfExportStylerDefaultImpl.class); 42 | 43 | @Override 44 | public Document getDocument() { 45 | return new Document(PageSize.A4, 36, 36, 24, 36); 46 | } 47 | 48 | @Override 49 | public void setCellStyler(PdfPCell iCell, ExcelExportEntity entity, String text) { 50 | iCell.setHorizontalAlignment(Element.ALIGN_CENTER); 51 | iCell.setVerticalAlignment(Element.ALIGN_MIDDLE); 52 | } 53 | 54 | @Override 55 | public Font getFont(ExcelExportEntity entity, String text) { 56 | try { 57 | //用以支持中文 58 | BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", 59 | BaseFont.NOT_EMBEDDED); 60 | Font font = new Font(bfChinese); 61 | return font; 62 | } catch (DocumentException e) { 63 | LOGGER.error(e.getMessage(), e); 64 | } catch (IOException e) { 65 | LOGGER.error(e.getMessage(), e); 66 | } 67 | Font font = new Font(FontFamily.UNDEFINED); 68 | return font; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/cn/afterturn/easypoi/view/EasypoiTemplateWordView.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 cn.afterturn.easypoi.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 cn.afterturn.easypoi.util.WebFilenameUtils; 25 | import org.apache.poi.xwpf.usermodel.XWPFDocument; 26 | import org.springframework.stereotype.Controller; 27 | 28 | import cn.afterturn.easypoi.entity.vo.TemplateWordConstants; 29 | import cn.afterturn.easypoi.word.WordExportUtil; 30 | 31 | /** 32 | * Word模板视图 33 | * 34 | * @author JueYue 35 | * 2014年6月30日 下午9:15:49 36 | */ 37 | @SuppressWarnings("unchecked") 38 | @Controller(TemplateWordConstants.EASYPOI_TEMPLATE_WORD_VIEW) 39 | public class EasypoiTemplateWordView extends PoiBaseView { 40 | 41 | private static final String CONTENT_TYPE = "application/msword"; 42 | 43 | public EasypoiTemplateWordView() { 44 | setContentType(CONTENT_TYPE); 45 | } 46 | 47 | @Override 48 | protected void renderMergedOutputModel(Map model, HttpServletRequest request, 49 | HttpServletResponse response) throws Exception { 50 | String codedFileName = "临时文件.docx"; 51 | if (model.containsKey(TemplateWordConstants.FILE_NAME)) { 52 | codedFileName = (String) model.get(TemplateWordConstants.FILE_NAME) + ".docx"; 53 | } 54 | // 用工具类生成符合RFC 5987标准的文件名header, 去掉UA判断 55 | response.setHeader("content-disposition", WebFilenameUtils.disposition(codedFileName)); 56 | XWPFDocument document = WordExportUtil.exportWord07( 57 | (String) model.get(TemplateWordConstants.URL), 58 | (Map) model.get(TemplateWordConstants.MAP_DATA)); 59 | ServletOutputStream out = response.getOutputStream(); 60 | document.write(out); 61 | out.flush(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/cn/afterturn/easypoi/view/EasypoiTemplateExcelView.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 cn.afterturn.easypoi.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.springframework.stereotype.Controller; 28 | 29 | import cn.afterturn.easypoi.entity.vo.NormalExcelConstants; 30 | import cn.afterturn.easypoi.entity.vo.TemplateExcelConstants; 31 | import cn.afterturn.easypoi.excel.ExcelExportUtil; 32 | import cn.afterturn.easypoi.excel.entity.TemplateExportParams; 33 | 34 | /** 35 | * Excel模板视图 36 | * 37 | * @author JueYue 38 | * 2014年6月30日 下午9:15:49 39 | */ 40 | @SuppressWarnings("unchecked") 41 | @Controller(TemplateExcelConstants.EASYPOI_TEMPLATE_EXCEL_VIEW) 42 | public class EasypoiTemplateExcelView extends MiniAbstractExcelView { 43 | 44 | public EasypoiTemplateExcelView() { 45 | super(); 46 | } 47 | 48 | @Override 49 | protected void renderMergedOutputModel(Map model, HttpServletRequest request, 50 | HttpServletResponse response) throws Exception { 51 | String codedFileName = "临时文件"; 52 | @SuppressWarnings("deprecation") 53 | Workbook workbook = ExcelExportUtil.exportExcel( 54 | (TemplateExportParams) model.get(TemplateExcelConstants.PARAMS), 55 | (Class) model.get(TemplateExcelConstants.CLASS), 56 | (List) model.get(TemplateExcelConstants.LIST_DATA), 57 | (Map) model.get(TemplateExcelConstants.MAP_DATA)); 58 | if (model.containsKey(NormalExcelConstants.FILE_NAME)) { 59 | codedFileName = (String) model.get(NormalExcelConstants.FILE_NAME); 60 | } 61 | out(workbook, codedFileName, request, response); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/entity/HtmlCssConstant.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2017 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 cn.afterturn.easypoi.excel.html.entity; 17 | 18 | public interface HtmlCssConstant { 19 | 20 | // constants 21 | public final String PATTERN_LENGTH = "\\d*\\.?\\d+\\s*(?:em|ex|cm|mm|q|in|pt|pc|px)?"; 22 | public final String STYLE = "style"; 23 | // direction 24 | public final String TOP = "top"; 25 | public final String RIGHT = "right"; 26 | public final String BOTTOM = "bottom"; 27 | public final String LEFT = "left"; 28 | public final String WIDTH = "width"; 29 | public final String HEIGHT = "height"; 30 | public final String COLOR = "color"; 31 | public final String BORDER = "border"; 32 | public final String CENTER = "center"; 33 | public final String JUSTIFY = "justify"; 34 | public final String MIDDLE = "middle"; 35 | public final String FONT = "font"; 36 | public final String FONT_STYLE = "font-style"; 37 | public final String FONT_WEIGHT = "font-weight"; 38 | public final String FONT_SIZE = "font-size"; 39 | public final String FONT_FAMILY = "font-family"; 40 | public final String TEXT_DECORATION = "text-decoration"; 41 | public final String UNDERLINE = "underline"; 42 | public final String ITALIC = "italic"; 43 | public final String BOLD = "bold"; 44 | public final String NORMAL = "normal"; 45 | public final String TEXT_ALIGN = "text-align"; 46 | public final String VETICAL_ALIGN = "vertical-align"; 47 | public final String BACKGROUND = "background"; 48 | public final String BACKGROUND_COLOR = "background-color"; 49 | public final String NONE = "none"; 50 | public final String HIDDEN = "hidden"; 51 | public final String SOLID = "solid"; 52 | public final String DOUBLE = "double"; 53 | public final String DOTTED = "dotted"; 54 | public final String DASHED = "dashed"; 55 | 56 | } 57 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/cache/manager/FileLoaderImpl.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 cn.afterturn.easypoi.cache.manager; 17 | 18 | import cn.afterturn.easypoi.util.PoiPublicUtil; 19 | import org.apache.poi.util.IOUtils; 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | 23 | import java.io.*; 24 | import java.net.URL; 25 | import java.net.URLConnection; 26 | 27 | /** 28 | * 文件加载类,根据路径加载指定文件 29 | * 30 | * @author JueYue 31 | * 2014年2月10日 32 | * @version 1.0 33 | */ 34 | public class FileLoaderImpl implements IFileLoader { 35 | 36 | private static final Logger LOGGER = LoggerFactory.getLogger(FileLoaderImpl.class); 37 | 38 | @Override 39 | public byte[] getFile(String url) { 40 | InputStream fileis = null; 41 | ByteArrayOutputStream baos = null; 42 | try { 43 | 44 | //判断是否是网络地址 45 | if (url.startsWith("http")) { 46 | URL urlObj = new URL(url); 47 | URLConnection urlConnection = urlObj.openConnection(); 48 | urlConnection.setConnectTimeout(30 * 1000); 49 | urlConnection.setReadTimeout(60 * 1000); 50 | urlConnection.setDoInput(true); 51 | fileis = urlConnection.getInputStream(); 52 | } else { 53 | //先用绝对路径查询,再查询相对路径 54 | try { 55 | fileis = new FileInputStream(url); 56 | } catch (FileNotFoundException e) { 57 | //获取项目文件 58 | fileis = FileLoaderImpl.class.getClassLoader().getResourceAsStream(url); 59 | } 60 | } 61 | 62 | baos = new ByteArrayOutputStream(); 63 | byte[] buffer = new byte[1024]; 64 | int len; 65 | while ((len = fileis.read(buffer)) > -1) { 66 | baos.write(buffer, 0, len); 67 | } 68 | baos.flush(); 69 | return baos.toByteArray(); 70 | } catch (Exception e) { 71 | LOGGER.error(e.getMessage(), e); 72 | } finally { 73 | IOUtils.closeQuietly(fileis); 74 | IOUtils.closeQuietly(baos); 75 | } 76 | LOGGER.error(fileis + "这个路径文件没有找到,请查询"); 77 | return null; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.word.entity.params; 17 | 18 | import java.util.List; 19 | 20 | import cn.afterturn.easypoi.excel.entity.ExcelBaseParams; 21 | import cn.afterturn.easypoi.handler.inter.IExcelDataHandler; 22 | 23 | /** 24 | * Excel 导出对象 25 | * 26 | * @author JueYue 27 | * 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 dataHandler) { 56 | this.list = list; 57 | this.clazz = clazz; 58 | setDataHandler(dataHandler); 59 | } 60 | 61 | public ExcelListEntity(List list, Class clazz, IExcelDataHandler dataHandler, 62 | int headRows) { 63 | this.list = list; 64 | this.clazz = clazz; 65 | this.headRows = headRows; 66 | setDataHandler(dataHandler); 67 | } 68 | 69 | public ExcelListEntity(List list, Class clazz, int headRows) { 70 | this.list = list; 71 | this.clazz = clazz; 72 | this.headRows = headRows; 73 | } 74 | 75 | public Class getClazz() { 76 | return clazz; 77 | } 78 | 79 | public int getHeadRows() { 80 | return headRows; 81 | } 82 | 83 | public List getList() { 84 | return list; 85 | } 86 | 87 | public void setClazz(Class clazz) { 88 | this.clazz = clazz; 89 | } 90 | 91 | public void setHeadRows(int headRows) { 92 | this.headRows = headRows; 93 | } 94 | 95 | public void setList(List list) { 96 | this.list = list; 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.excel.export.styler; 17 | 18 | import org.apache.poi.ss.usermodel.*; 19 | 20 | /** 21 | * 样式的默认实现 22 | * @author JueYue 23 | * 2015年1月9日 下午5:36:08 24 | */ 25 | public class ExcelExportStylerDefaultImpl extends AbstractExcelExportStyler 26 | implements IExcelExportStyler { 27 | 28 | public ExcelExportStylerDefaultImpl(Workbook workbook) { 29 | super.createStyles(workbook); 30 | } 31 | 32 | @Override 33 | public CellStyle getTitleStyle(short color) { 34 | CellStyle titleStyle = workbook.createCellStyle(); 35 | titleStyle.setAlignment(HorizontalAlignment.CENTER); 36 | titleStyle.setVerticalAlignment(VerticalAlignment.CENTER); 37 | titleStyle.setWrapText(true); 38 | return titleStyle; 39 | } 40 | 41 | @Override 42 | public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) { 43 | CellStyle style = workbook.createCellStyle(); 44 | style.setAlignment(HorizontalAlignment.CENTER); 45 | style.setVerticalAlignment(VerticalAlignment.CENTER); 46 | style.setDataFormat(STRING_FORMAT); 47 | if (isWarp) { 48 | style.setWrapText(true); 49 | } 50 | return style; 51 | } 52 | 53 | @Override 54 | public CellStyle getHeaderStyle(short color) { 55 | CellStyle titleStyle = workbook.createCellStyle(); 56 | Font font = workbook.createFont(); 57 | font.setFontHeightInPoints((short) 12); 58 | titleStyle.setFont(font); 59 | titleStyle.setAlignment(HorizontalAlignment.CENTER); 60 | titleStyle.setVerticalAlignment(VerticalAlignment.CENTER); 61 | return titleStyle; 62 | } 63 | 64 | @Override 65 | public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) { 66 | CellStyle style = workbook.createCellStyle(); 67 | style.setAlignment(HorizontalAlignment.CENTER); 68 | style.setVerticalAlignment(VerticalAlignment.CENTER); 69 | style.setDataFormat(STRING_FORMAT); 70 | if (isWarp) { 71 | style.setWrapText(true); 72 | } 73 | return style; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/cn/afterturn/easypoi/view/PoiBaseView.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 cn.afterturn.easypoi.view; 17 | 18 | import java.util.Map; 19 | 20 | import javax.servlet.http.HttpServletRequest; 21 | import javax.servlet.http.HttpServletResponse; 22 | 23 | import org.slf4j.Logger; 24 | import org.slf4j.LoggerFactory; 25 | import org.springframework.web.servlet.view.AbstractView; 26 | 27 | import cn.afterturn.easypoi.entity.vo.BigExcelConstants; 28 | import cn.afterturn.easypoi.entity.vo.MapExcelConstants; 29 | import cn.afterturn.easypoi.entity.vo.MapExcelGraphConstants; 30 | import cn.afterturn.easypoi.entity.vo.NormalExcelConstants; 31 | import cn.afterturn.easypoi.entity.vo.TemplateExcelConstants; 32 | 33 | /** 34 | * 提供一些通用结构 35 | */ 36 | public abstract class PoiBaseView extends AbstractView { 37 | 38 | private static final Logger LOGGER = LoggerFactory.getLogger(PoiBaseView.class); 39 | 40 | protected static boolean isIE(HttpServletRequest request) { 41 | return (request.getHeader("USER-AGENT").toLowerCase().indexOf("msie") > 0 42 | || request.getHeader("USER-AGENT").toLowerCase().indexOf("rv:11.0") > 0 43 | || request.getHeader("USER-AGENT").toLowerCase().indexOf("edge") > 0) ? true 44 | : false; 45 | } 46 | 47 | public static void render(Map model, HttpServletRequest request, 48 | HttpServletResponse response, String viewName) { 49 | PoiBaseView view = null; 50 | if (BigExcelConstants.EASYPOI_BIG_EXCEL_VIEW.equals(viewName)) { 51 | view = new EasypoiBigExcelExportView(); 52 | } else if (MapExcelConstants.EASYPOI_MAP_EXCEL_VIEW.equals(viewName)) { 53 | view = new EasypoiMapExcelView(); 54 | } else if (NormalExcelConstants.EASYPOI_EXCEL_VIEW.equals(viewName)) { 55 | view = new EasypoiSingleExcelView(); 56 | } else if (TemplateExcelConstants.EASYPOI_TEMPLATE_EXCEL_VIEW.equals(viewName)) { 57 | view = new EasypoiTemplateExcelView(); 58 | } else if (MapExcelGraphConstants.MAP_GRAPH_EXCEL_VIEW.equals(viewName)) { 59 | view = new MapGraphExcelView(); 60 | } 61 | try { 62 | view.renderMergedOutputModel(model, request, response); 63 | } catch (Exception e) { 64 | LOGGER.error(e.getMessage(), e); 65 | } 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/entity/ImageEntity.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 cn.afterturn.easypoi.entity; 17 | 18 | /** 19 | * word导出,图片设置和图片信息 20 | * 21 | * @author JueYue 22 | * 2017-9-15 23 | * @version 3.0.1 24 | */ 25 | public class ImageEntity { 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 | private int rowspan = 1; 45 | private int colspan = 1; 46 | 47 | 48 | public ImageEntity() { 49 | 50 | } 51 | 52 | public ImageEntity(byte[] data, int width, int height) { 53 | this.data = data; 54 | this.width = width; 55 | this.height = height; 56 | this.type = Data; 57 | } 58 | 59 | public ImageEntity(String url, int width, int height) { 60 | this.url = url; 61 | this.width = width; 62 | this.height = height; 63 | } 64 | 65 | public byte[] getData() { 66 | return data; 67 | } 68 | 69 | public int getHeight() { 70 | return height; 71 | } 72 | 73 | public String getType() { 74 | return type; 75 | } 76 | 77 | public String getUrl() { 78 | return url; 79 | } 80 | 81 | public int getWidth() { 82 | return width; 83 | } 84 | 85 | public void setData(byte[] data) { 86 | this.data = data; 87 | } 88 | 89 | public void setHeight(int height) { 90 | this.height = height; 91 | } 92 | 93 | public void setType(String type) { 94 | this.type = type; 95 | } 96 | 97 | public void setUrl(String url) { 98 | this.url = url; 99 | } 100 | 101 | public void setWidth(int width) { 102 | this.width = width; 103 | } 104 | 105 | public int getRowspan() { 106 | return rowspan; 107 | } 108 | 109 | public void setRowspan(int rowspan) { 110 | this.rowspan = rowspan; 111 | } 112 | 113 | public int getColspan() { 114 | return colspan; 115 | } 116 | 117 | public void setColspan(int colspan) { 118 | this.colspan = colspan; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/cn/afterturn/easypoi/view/MapGraphExcelView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013-2015 xfworld (xfworld@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 cn.afterturn.easypoi.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.springframework.stereotype.Controller; 28 | 29 | import cn.afterturn.easypoi.view.MiniAbstractExcelView; 30 | import cn.afterturn.easypoi.entity.vo.MapExcelGraphConstants; 31 | import cn.afterturn.easypoi.excel.ExcelExportUtil; 32 | import cn.afterturn.easypoi.excel.entity.ExportParams; 33 | import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; 34 | import cn.afterturn.easypoi.excel.graph.builder.ExcelChartBuildService; 35 | import cn.afterturn.easypoi.excel.graph.entity.ExcelGraph; 36 | 37 | /** 38 | * Map 对象接口 39 | * 40 | * @author xfworld 41 | * @since 2016-01-04 42 | */ 43 | @SuppressWarnings("unchecked") 44 | @Controller(MapExcelGraphConstants.MAP_GRAPH_EXCEL_VIEW) 45 | public class MapGraphExcelView extends MiniAbstractExcelView { 46 | 47 | public MapGraphExcelView() { 48 | super(); 49 | } 50 | 51 | @Override 52 | protected void renderMergedOutputModel(Map model, HttpServletRequest request, 53 | HttpServletResponse response) throws Exception { 54 | String codedFileName = "临时文件"; 55 | ExportParams params=(ExportParams)model.get(MapExcelGraphConstants.PARAMS); 56 | List entityList=(List) model.get(MapExcelGraphConstants.ENTITY_LIST); 57 | List> mapList=(List>)model.get(MapExcelGraphConstants.MAP_LIST); 58 | List graphDefinedList=(List)model.get(MapExcelGraphConstants.GRAPH_DEFINED); 59 | //构建数据 60 | Workbook workbook = ExcelExportUtil.exportExcel(params,entityList,mapList); 61 | ExcelChartBuildService.createExcelChart(workbook,graphDefinedList, params.isDynamicData(), params.isAppendGraph()); 62 | 63 | if (model.containsKey(MapExcelGraphConstants.FILE_NAME)) { 64 | codedFileName = (String) model.get(MapExcelGraphConstants.FILE_NAME); 65 | } 66 | out(workbook, codedFileName, request, response); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/ExcelToHtmlParams.java: -------------------------------------------------------------------------------- 1 | package cn.afterturn.easypoi.excel.entity; 2 | 3 | import lombok.Data; 4 | import org.apache.poi.ss.usermodel.Workbook; 5 | 6 | /** 7 | * Excel到HTML的参数 8 | * @author JueYue 9 | * 2015年8月7日 下午1:45:46 10 | */ 11 | @Data 12 | public class ExcelToHtmlParams { 13 | /** 14 | * Excel 15 | */ 16 | private Workbook wb; 17 | /** 18 | * 是不是全界面 19 | */ 20 | private boolean completeHTML = false; 21 | /** 22 | * 位置 23 | */ 24 | private int sheetNum = 0; 25 | 26 | /** 27 | * -- 图片保存路径,/开始或者含有: 认为是绝对路径,其他是相对路径,每次img名称随机生成,按照天生成文件夹 28 | * -- 不生成图片了直接BASE64Encoder 29 | * 不为空就认为显示图片 30 | */ 31 | private String path = null; 32 | 33 | private boolean showRowNum = false; 34 | private boolean showColumnHead = false; 35 | 36 | public ExcelToHtmlParams(Workbook wb) { 37 | this.wb = wb; 38 | } 39 | 40 | public ExcelToHtmlParams(Workbook wb, boolean completeHTML) { 41 | this.wb = wb; 42 | this.completeHTML = completeHTML; 43 | } 44 | 45 | public ExcelToHtmlParams(Workbook wb, int sheetNum) { 46 | this.wb = wb; 47 | this.sheetNum = sheetNum; 48 | } 49 | 50 | public ExcelToHtmlParams(Workbook wb, String path) { 51 | this.wb = wb; 52 | this.path = path; 53 | } 54 | 55 | public ExcelToHtmlParams(Workbook wb, int sheetNum, String path) { 56 | this.wb = wb; 57 | this.sheetNum = sheetNum; 58 | this.path = path; 59 | } 60 | 61 | public ExcelToHtmlParams(Workbook wb, boolean completeHTML, String path) { 62 | this.wb = wb; 63 | this.completeHTML = completeHTML; 64 | this.path = path; 65 | } 66 | 67 | public ExcelToHtmlParams(Workbook wb, boolean completeHTML, int sheetNum, String path) { 68 | this.wb = wb; 69 | this.completeHTML = completeHTML; 70 | this.sheetNum = sheetNum; 71 | this.path = path; 72 | } 73 | 74 | @Override 75 | public boolean equals(Object obj) { 76 | if (obj instanceof ExcelToHtmlParams) { 77 | ExcelToHtmlParams other = (ExcelToHtmlParams) obj; 78 | if (!this.wb.equals(other.getWb()) || this.completeHTML != other.completeHTML 79 | || this.sheetNum != other.getSheetNum()) { 80 | return false; 81 | } 82 | if ((this.path == null && other.getPath() != null) 83 | || !this.path.equals(other.getPath())) { 84 | return false; 85 | } 86 | return true; 87 | } 88 | return false; 89 | } 90 | 91 | /** 92 | * 保持一个参数一个对象的hashCode 93 | */ 94 | @Override 95 | public int hashCode() { 96 | StringBuilder sb = new StringBuilder(); 97 | sb.append(wb.hashCode()); 98 | sb.append(path); 99 | sb.append(completeHTML); 100 | sb.append(sheetNum); 101 | return sb.toString().hashCode(); 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.excel.export.styler; 17 | 18 | import org.apache.poi.ss.usermodel.BuiltinFormats; 19 | import org.apache.poi.ss.usermodel.Cell; 20 | import org.apache.poi.ss.usermodel.CellStyle; 21 | import org.apache.poi.ss.usermodel.Workbook; 22 | 23 | import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; 24 | import cn.afterturn.easypoi.excel.entity.params.ExcelForEachParams; 25 | 26 | /** 27 | * 抽象接口提供两个公共方法 28 | * 29 | * @author JueYue 2015年1月9日 下午5:48:55 30 | */ 31 | public abstract class AbstractExcelExportStyler implements IExcelExportStyler { 32 | //单行 33 | protected CellStyle stringNoneStyle; 34 | protected CellStyle stringNoneWrapStyle; 35 | //间隔行 36 | protected CellStyle stringSeptailStyle; 37 | protected CellStyle stringSeptailWrapStyle; 38 | 39 | protected Workbook workbook; 40 | 41 | protected static final short STRING_FORMAT = (short) BuiltinFormats.getBuiltinFormat("TEXT"); 42 | 43 | protected void createStyles(Workbook workbook) { 44 | this.stringNoneStyle = stringNoneStyle(workbook, false); 45 | this.stringNoneWrapStyle = stringNoneStyle(workbook, true); 46 | this.stringSeptailStyle = stringSeptailStyle(workbook, false); 47 | this.stringSeptailWrapStyle = stringSeptailStyle(workbook, true); 48 | this.workbook = workbook; 49 | } 50 | 51 | @Override 52 | public CellStyle getStyles(boolean noneStyler, ExcelExportEntity entity) { 53 | if (noneStyler && (entity == null || entity.isWrap())) { 54 | return stringNoneWrapStyle; 55 | } 56 | if (noneStyler) { 57 | return stringNoneStyle; 58 | } 59 | if (noneStyler == false && (entity == null || entity.isWrap())) { 60 | return stringSeptailWrapStyle; 61 | } 62 | return stringSeptailStyle; 63 | } 64 | 65 | @Override 66 | public CellStyle getStyles(Cell cell, int dataRow, ExcelExportEntity entity, Object obj, Object data) { 67 | return getStyles(dataRow % 2 == 1, entity); 68 | } 69 | 70 | public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) { 71 | return null; 72 | } 73 | 74 | public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) { 75 | return null; 76 | } 77 | 78 | 79 | @Override 80 | public CellStyle getTemplateStyles(boolean isSingle, ExcelForEachParams excelForEachParams) { 81 | return null; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/entity/style/CellStyleEntity.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 cn.afterturn.easypoi.excel.html.entity.style; 17 | 18 | /** 19 | * Cell 具有的样式 20 | * @author JueYue 21 | * 2016年3月20日 下午4:56:51 22 | */ 23 | public class CellStyleEntity { 24 | /** 25 | * 宽 26 | */ 27 | private String width; 28 | /** 29 | * 高 30 | */ 31 | private String height; 32 | /** 33 | * 边框 34 | */ 35 | private CellStyleBorderEntity border; 36 | /** 37 | * 背景 38 | */ 39 | private String background; 40 | /** 41 | * 水平位置 42 | */ 43 | private String align; 44 | /** 45 | * 垂直位置 46 | */ 47 | private String vetical; 48 | /** 49 | * 字体设置 50 | */ 51 | private CssStyleFontEnity font; 52 | 53 | public String getWidth() { 54 | return width; 55 | } 56 | 57 | public void setWidth(String width) { 58 | this.width = width; 59 | } 60 | 61 | public String getHeight() { 62 | return height; 63 | } 64 | 65 | public void setHeight(String height) { 66 | this.height = height; 67 | } 68 | 69 | public CellStyleBorderEntity getBorder() { 70 | return border; 71 | } 72 | 73 | public void setBorder(CellStyleBorderEntity border) { 74 | this.border = border; 75 | } 76 | 77 | public String getBackground() { 78 | return background; 79 | } 80 | 81 | public void setBackground(String background) { 82 | this.background = background; 83 | } 84 | 85 | public String getAlign() { 86 | return align; 87 | } 88 | 89 | public void setAlign(String align) { 90 | this.align = align; 91 | } 92 | 93 | public String getVetical() { 94 | return vetical; 95 | } 96 | 97 | public void setVetical(String vetical) { 98 | this.vetical = vetical; 99 | } 100 | 101 | public CssStyleFontEnity getFont() { 102 | return font; 103 | } 104 | 105 | public void setFont(CssStyleFontEnity font) { 106 | this.font = font; 107 | } 108 | 109 | @Override 110 | public String toString() { 111 | return new StringBuilder().append(align).append(background).append(border).append(height) 112 | .append(vetical).append(width).append(font).toString(); 113 | } 114 | 115 | } 116 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiValidationUtil.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 cn.afterturn.easypoi.util; 17 | 18 | import cn.afterturn.easypoi.excel.annotation.Excel; 19 | 20 | import java.lang.reflect.Field; 21 | import java.util.ArrayList; 22 | import java.util.Arrays; 23 | import java.util.List; 24 | import java.util.Set; 25 | 26 | import javax.validation.ConstraintViolation; 27 | import javax.validation.Validation; 28 | import javax.validation.Validator; 29 | import javax.validation.ValidatorFactory; 30 | 31 | /** 32 | * HIBERNATE 校验工具类 33 | * @author JueYue 34 | * 2015年11月11日 下午10:04:07 35 | */ 36 | public class PoiValidationUtil { 37 | 38 | private final static Validator VALIDATOR; 39 | 40 | static { 41 | ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); 42 | VALIDATOR = factory.getValidator(); 43 | } 44 | 45 | public static String validation(Object obj, Class[] verfiyGroup) { 46 | Set> set = null; 47 | if(verfiyGroup != null){ 48 | set = VALIDATOR.validate(obj,verfiyGroup); 49 | }else{ 50 | set = VALIDATOR.validate(obj); 51 | } 52 | if (set!= null && set.size() > 0) { 53 | return getValidateErrMsg(set); 54 | } 55 | return null; 56 | } 57 | 58 | private static String getValidateErrMsg(Set> set) { 59 | StringBuilder builder = new StringBuilder(); 60 | for (ConstraintViolation constraintViolation : set) { 61 | Class cls = constraintViolation.getRootBean().getClass(); 62 | String fieldName = constraintViolation.getPropertyPath().toString(); 63 | List fields = new ArrayList<>(Arrays.asList(cls.getDeclaredFields())); 64 | Class superClass = cls.getSuperclass(); 65 | if (superClass != null) { 66 | fields.addAll(Arrays.asList(superClass.getDeclaredFields())); 67 | } 68 | String name = null; 69 | for (Field field: fields) { 70 | if (field.getName().equals(fieldName) && field.isAnnotationPresent(Excel.class)) { 71 | name = field.getAnnotation(Excel.class).name(); 72 | break; 73 | } 74 | } 75 | if (name == null) { 76 | name = fieldName; 77 | } 78 | builder.append(name).append(constraintViolation.getMessage()).append(","); 79 | } 80 | return builder.substring(0, builder.length() - 1); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/excel/html/css/impl/TextCssConvertImpl.java: -------------------------------------------------------------------------------- 1 | package cn.afterturn.easypoi.excel.html.css.impl; 2 | 3 | import static cn.afterturn.easypoi.excel.html.entity.HtmlCssConstant.*; 4 | import static org.apache.poi.ss.usermodel.IndexedColors.BLACK; 5 | 6 | import org.apache.commons.lang3.StringUtils; 7 | import org.apache.poi.hssf.usermodel.HSSFFont; 8 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; 9 | import org.apache.poi.hssf.util.HSSFColor; 10 | import org.apache.poi.ss.usermodel.Cell; 11 | import org.apache.poi.ss.usermodel.CellStyle; 12 | import org.apache.poi.ss.usermodel.Font; 13 | import org.apache.poi.ss.usermodel.Workbook; 14 | import org.apache.poi.xssf.usermodel.XSSFColor; 15 | import org.apache.poi.xssf.usermodel.XSSFFont; 16 | 17 | import cn.afterturn.easypoi.excel.html.css.ICssConvertToExcel; 18 | import cn.afterturn.easypoi.excel.html.css.ICssConvertToHtml; 19 | import cn.afterturn.easypoi.excel.html.entity.style.CellStyleEntity; 20 | import cn.afterturn.easypoi.util.PoiCssUtils; 21 | 22 | /** 23 | * @author jueyue 24 | */ 25 | public class TextCssConvertImpl implements ICssConvertToExcel, ICssConvertToHtml { 26 | 27 | @Override 28 | public String convertToHtml(Cell cell, CellStyle cellStyle, CellStyleEntity style) { 29 | 30 | return null; 31 | } 32 | 33 | @Override 34 | public void convertToExcel(Cell cell, CellStyle cellStyle, CellStyleEntity style) { 35 | if (style == null || style.getFont() == null) { 36 | return; 37 | } 38 | Font font = cell.getSheet().getWorkbook().createFont(); 39 | if (ITALIC.equals(style.getFont().getStyle())) { 40 | font.setItalic(true); 41 | } 42 | int fontSize = style.getFont().getSize(); 43 | if (fontSize > 0) { 44 | font.setFontHeightInPoints((short) fontSize); 45 | } 46 | if (BOLD.equals(style.getFont().getWeight())) { 47 | font.setBold(true); 48 | } 49 | String fontFamily = style.getFont().getFamily(); 50 | if (StringUtils.isNotBlank(fontFamily)) { 51 | font.setFontName(fontFamily); 52 | } 53 | String color = style.getFont().getColor(); 54 | if (StringUtils.isNoneEmpty(color)) { 55 | if (font instanceof HSSFFont) { 56 | setFontForHSSF(font, cell.getSheet().getWorkbook(), color); 57 | } else if (font instanceof XSSFFont) { 58 | setFontForXSSF(font, color); 59 | } 60 | } 61 | if (UNDERLINE.equals(style.getFont().getDecoration())) { 62 | font.setUnderline(Font.U_SINGLE); 63 | } 64 | cellStyle.setFont(font); 65 | } 66 | 67 | private void setFontForXSSF(Font font, String colorStr) { 68 | XSSFColor color = PoiCssUtils.parseColor(colorStr); 69 | ((XSSFFont)font).setColor(color); 70 | } 71 | 72 | private void setFontForHSSF(Font font, Workbook workbook, String colorStr) { 73 | HSSFColor color = PoiCssUtils.parseColor((HSSFWorkbook) workbook, colorStr); 74 | if (color != null) { 75 | if (color.getIndex() != BLACK.index) { 76 | font.setColor(color.getIndex()); 77 | } 78 | } 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /easypoi-base/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | cn.afterturn 6 | easypoi 7 | 4.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 | org.apache.poi 44 | poi-scratchpad 45 | true 46 | 47 | 48 | org.apache.xmlbeans 49 | xmlbeans 50 | true 51 | 52 | 53 | 54 | 55 | com.itextpdf 56 | itextpdf 57 | true 58 | 59 | 60 | com.itextpdf 61 | itext-asian 62 | true 63 | 64 | 65 | 66 | 67 | org.jsoup 68 | jsoup 69 | true 70 | 71 | 72 | 73 | 74 | com.google.guava 75 | guava 76 | 77 | 78 | 79 | org.apache.commons 80 | commons-lang3 81 | 82 | 83 | 84 | ognl 85 | ognl 86 | 87 | 88 | 89 | 90 | org.slf4j 91 | slf4j-api 92 | 93 | 94 | 95 | javax.validation 96 | validation-api 97 | 98 | 99 | 100 | org.projectlombok 101 | lombok 102 | provided 103 | 104 | 105 | 106 | cn.afterturn 107 | easypoi-annotation 108 | 109 | 110 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/cn/afterturn/easypoi/view/EasypoiPDFTemplateView.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 cn.afterturn.easypoi.view; 17 | 18 | import java.io.ByteArrayOutputStream; 19 | import java.util.Collection; 20 | import java.util.List; 21 | import java.util.Map; 22 | 23 | import javax.servlet.http.HttpServletRequest; 24 | import javax.servlet.http.HttpServletResponse; 25 | 26 | import cn.afterturn.easypoi.util.WebFilenameUtils; 27 | import org.apache.commons.lang3.StringUtils; 28 | import org.springframework.stereotype.Controller; 29 | 30 | import cn.afterturn.easypoi.entity.vo.PDFTemplateConstants; 31 | import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity; 32 | import cn.afterturn.easypoi.pdf.PdfExportUtil; 33 | import cn.afterturn.easypoi.pdf.entity.PdfExportParams; 34 | 35 | /** 36 | * PDF 导出 View 37 | * @author JueYue 38 | * 2016年1月19日 上午10:43:02 39 | */ 40 | @Controller(PDFTemplateConstants.EASYPOI_PDF_TEMPLATE_VIEW) 41 | public class EasypoiPDFTemplateView extends PoiBaseView { 42 | 43 | public EasypoiPDFTemplateView() { 44 | setContentType("application/pdf"); 45 | } 46 | 47 | @Override 48 | protected boolean generatesDownloadContent() { 49 | return true; 50 | } 51 | 52 | @Override 53 | @SuppressWarnings("unchecked") 54 | protected final void renderMergedOutputModel(Map model, 55 | HttpServletRequest request, 56 | HttpServletResponse response) throws Exception { 57 | String fileName = "临时文件"; 58 | ByteArrayOutputStream baos = createTemporaryOutputStream(); 59 | PdfExportParams entity = (PdfExportParams) model.get(PDFTemplateConstants.PARAMS); 60 | Class pojoClass = (Class) model.get(PDFTemplateConstants.CLASS); 61 | Collection dataSet = (Collection) model.get(PDFTemplateConstants.DATA_LIST); 62 | List entityList = (List) model 63 | .get(PDFTemplateConstants.ENTITY_LIST); 64 | if (entityList == null) { 65 | PdfExportUtil.exportPdf(entity, pojoClass, dataSet, baos); 66 | } else { 67 | PdfExportUtil.exportPdf(entity, entityList, (Collection>) dataSet, 68 | baos); 69 | } 70 | String userFileName = (String) model.get(PDFTemplateConstants.FILE_NAME); 71 | if (StringUtils.isNoneBlank(userFileName)) { 72 | fileName = userFileName; 73 | } 74 | // 用工具类生成符合RFC 5987标准的文件名header, 去掉UA判断 75 | response.setHeader("content-disposition", WebFilenameUtils.disposition(fileName + ".pdf")); 76 | writeToResponse(response, baos); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.excel.export.styler; 17 | 18 | import org.apache.poi.ss.usermodel.*; 19 | import org.apache.poi.util.Removal; 20 | 21 | /** 22 | * 带有边框的Excel样式 23 | * 24 | * @author JueYue 25 | * 2015年1月9日 下午5:55:29 26 | */ 27 | @Deprecated 28 | @Removal( 29 | version = "4.2" 30 | ) 31 | public class ExcelExportStylerBorderImpl extends AbstractExcelExportStyler 32 | implements IExcelExportStyler { 33 | 34 | public ExcelExportStylerBorderImpl(Workbook workbook) { 35 | super.createStyles(workbook); 36 | } 37 | 38 | @Override 39 | public CellStyle getHeaderStyle(short color) { 40 | CellStyle titleStyle = workbook.createCellStyle(); 41 | Font font = workbook.createFont(); 42 | font.setFontHeightInPoints((short) 12); 43 | titleStyle.setFont(font); 44 | titleStyle.setBorderLeft(BorderStyle.THIN); 45 | titleStyle.setBorderRight(BorderStyle.THIN); 46 | titleStyle.setBorderBottom(BorderStyle.THIN); 47 | titleStyle.setBorderTop(BorderStyle.THIN); 48 | titleStyle.setAlignment(HorizontalAlignment.CENTER); 49 | titleStyle.setVerticalAlignment(VerticalAlignment.CENTER); 50 | return titleStyle; 51 | } 52 | 53 | @Override 54 | public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) { 55 | CellStyle style = workbook.createCellStyle(); 56 | style.setBorderLeft(BorderStyle.THIN); 57 | style.setBorderRight(BorderStyle.THIN); 58 | style.setBorderBottom(BorderStyle.THIN); 59 | style.setBorderTop(BorderStyle.THIN); 60 | style.setAlignment(HorizontalAlignment.CENTER); 61 | style.setVerticalAlignment(VerticalAlignment.CENTER); 62 | style.setDataFormat(STRING_FORMAT); 63 | if (isWarp) { 64 | style.setWrapText(true); 65 | } 66 | return style; 67 | } 68 | 69 | @Override 70 | public CellStyle getTitleStyle(short color) { 71 | CellStyle titleStyle = workbook.createCellStyle(); 72 | titleStyle.setBorderLeft(BorderStyle.THIN); 73 | titleStyle.setBorderRight(BorderStyle.THIN); 74 | titleStyle.setBorderBottom(BorderStyle.THIN); 75 | titleStyle.setBorderTop(BorderStyle.THIN); 76 | titleStyle.setAlignment(HorizontalAlignment.CENTER); 77 | titleStyle.setVerticalAlignment(VerticalAlignment.CENTER); 78 | titleStyle.setWrapText(true); 79 | return titleStyle; 80 | } 81 | 82 | @Override 83 | public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) { 84 | return isWarp ? stringNoneWrapStyle : stringNoneStyle; 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /easypoi-web/src/main/java/cn/afterturn/easypoi/view/EasypoiSingleExcelView.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 cn.afterturn.easypoi.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.springframework.stereotype.Controller; 29 | 30 | import cn.afterturn.easypoi.entity.vo.NormalExcelConstants; 31 | import cn.afterturn.easypoi.excel.ExcelExportUtil; 32 | import cn.afterturn.easypoi.excel.entity.ExportParams; 33 | import cn.afterturn.easypoi.excel.export.ExcelExportService; 34 | 35 | /** 36 | * @author JueYue on 14-3-8. Excel 生成解析器,减少用户操作 37 | */ 38 | @SuppressWarnings("unchecked") 39 | @Controller(NormalExcelConstants.EASYPOI_EXCEL_VIEW) 40 | public class EasypoiSingleExcelView extends MiniAbstractExcelView { 41 | 42 | public EasypoiSingleExcelView() { 43 | super(); 44 | } 45 | 46 | @Override 47 | protected void renderMergedOutputModel(Map model, HttpServletRequest request, 48 | HttpServletResponse response) throws Exception { 49 | String codedFileName = "临时文件"; 50 | Workbook workbook = null; 51 | if (model.containsKey(NormalExcelConstants.MAP_LIST)) { 52 | List> list = (List>) model 53 | .get(NormalExcelConstants.MAP_LIST); 54 | if (list.size() == 0) { 55 | throw new RuntimeException("MAP_LIST IS NULL"); 56 | } 57 | workbook = ExcelExportUtil.exportExcel( 58 | (ExportParams) list.get(0).get(NormalExcelConstants.PARAMS), (Class) list.get(0) 59 | .get(NormalExcelConstants.CLASS), 60 | (Collection) list.get(0).get(NormalExcelConstants.DATA_LIST)); 61 | for (int i = 1; i < list.size(); i++) { 62 | new ExcelExportService().createSheet(workbook, 63 | (ExportParams) list.get(i).get(NormalExcelConstants.PARAMS), (Class) list 64 | .get(i).get(NormalExcelConstants.CLASS), 65 | (Collection) list.get(i).get(NormalExcelConstants.DATA_LIST)); 66 | } 67 | } else { 68 | workbook = ExcelExportUtil.exportExcel( 69 | (ExportParams) model.get(NormalExcelConstants.PARAMS), 70 | (Class) model.get(NormalExcelConstants.CLASS), 71 | (Collection) model.get(NormalExcelConstants.DATA_LIST)); 72 | } 73 | if (model.containsKey(NormalExcelConstants.FILE_NAME)) { 74 | codedFileName = (String) model.get(NormalExcelConstants.FILE_NAME); 75 | } 76 | out(workbook, codedFileName, request, response); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.excel.entity; 17 | 18 | import cn.afterturn.easypoi.handler.inter.IExcelVerifyHandler; 19 | import lombok.Data; 20 | 21 | /** 22 | * 导入参数设置 23 | * 24 | * @author JueYue 25 | * 2013-9-24 26 | * @version 1.0 27 | */ 28 | @Data 29 | public class ImportParams extends ExcelBaseParams { 30 | 31 | public static final String SAVE_URL = "/excel/upload/excelUpload"; 32 | 33 | /** 34 | * 表格标题行数,默认0 35 | */ 36 | private int titleRows = 0; 37 | /** 38 | * 表头行数,默认1 39 | */ 40 | private int headRows = 1; 41 | /** 42 | * 字段真正值和列标题之间的距离 默认0 43 | */ 44 | private int startRows = 0; 45 | 46 | /** 47 | * 主键设置,如何这个cell没有值,就跳过 或者认为这个是list的下面的值 48 | * 大家不理解,去掉这个 49 | */ 50 | 51 | private Integer keyIndex = null; 52 | /** 53 | * 开始读取的sheet位置,默认为0 54 | */ 55 | private int startSheetIndex = 0; 56 | /** 57 | * 上传表格需要读取的sheet 数量,默认为1 58 | */ 59 | private int sheetNum = 1; 60 | /** 61 | * 是否需要保存上传的Excel,默认为false 62 | */ 63 | private boolean needSave = false; 64 | /** 65 | * 校验组 66 | */ 67 | private Class[] verifyGroup = null; 68 | /** 69 | * 是否需要校验上传的Excel,默认为false 70 | */ 71 | private boolean needVerify = false; 72 | /** 73 | * 返回文件是否分割,默认是分割 74 | */ 75 | private boolean verifyFileSplit = true; 76 | /** 77 | * 校验处理接口 78 | */ 79 | private IExcelVerifyHandler verifyHandler; 80 | /** 81 | * 保存上传的Excel目录,默认是 如 TestEntity这个类保存路径就是 82 | * upload/excelUpload/Test/yyyyMMddHHmss_***** 保存名称上传时间_五位随机数 83 | */ 84 | private String saveUrl = SAVE_URL; 85 | /** 86 | * 最后的无效行数 87 | */ 88 | private int lastOfInvalidRow = 0; 89 | /** 90 | * 手动控制读取的行数 91 | */ 92 | private int readRows = 0; 93 | /** 94 | * 导入时校验数据模板,是不是正确的Excel 95 | */ 96 | private String[] importFields; 97 | /** 98 | * 导入时校验excel的标题列顺序。依赖于importFields的配置顺序 99 | */ 100 | private boolean needCheckOrder = false; 101 | /** 102 | * Key-Value 读取标记,以这个为Key,后面一个Cell 为Value,多个改为ArrayList 103 | */ 104 | private String keyMark = ":"; 105 | /** 106 | * 按照Key-Value 规则读取全局扫描Excel,但是跳过List读取范围提升性能 107 | * 仅仅支持titleRows + headRows + startRows 以及 lastOfInvalidRow 108 | */ 109 | private boolean readSingleCell = false; 110 | /** 111 | * 是否并行计算 112 | */ 113 | private boolean concurrentTask = false; 114 | /** 115 | * 最小截取大小 116 | */ 117 | private Integer critical = 1000; 118 | } 119 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiExcelTempUtil.java: -------------------------------------------------------------------------------- 1 | package cn.afterturn.easypoi.util; 2 | 3 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; 4 | import org.apache.poi.ss.usermodel.*; 5 | 6 | import java.util.Date; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | /** 11 | * poi 4.0 07版本在 shift操作下有bug,不移动了单元格以及单元格样式,没有移动cell 12 | * cell还是复用的原理的cell,导致wb输出的时候没有输出值 13 | * 等待修复的时候删除这个问题 14 | * 15 | * @author by jueyue on 19-6-17. 16 | */ 17 | public class PoiExcelTempUtil { 18 | 19 | /** 20 | * 把这N行的数据,cell重新设置下,修复因为shift的浅复制问题,导致文本不显示的错误 21 | * 22 | * @param sheet 23 | * @param startRow 24 | * @param endRow 25 | */ 26 | public static void reset(Sheet sheet, int startRow, int endRow) { 27 | if (sheet.getWorkbook() instanceof HSSFWorkbook) { 28 | return; 29 | } 30 | for (int i = startRow; i <= endRow; i++) { 31 | Row row = sheet.getRow(i); 32 | if (row == null) { 33 | continue; 34 | } 35 | int cellNum = row.getLastCellNum(); 36 | for (int j = 0; j < cellNum; j++) { 37 | if (row.getCell(j) == null) { 38 | continue; 39 | } 40 | Map map = copyCell(row.getCell(j)); 41 | row.removeCell(row.getCell(j)); 42 | Cell cell = row.createCell(j); 43 | cell.setCellStyle((CellStyle) map.get("cellStyle")); 44 | if ((boolean) map.get("isDate")) { 45 | cell.setCellValue((Date) map.get("value")); 46 | } else { 47 | CellType cellType = (CellType) map.get("cellType"); 48 | switch (cellType) { 49 | case NUMERIC: 50 | cell.setCellValue((double) map.get("value")); 51 | break; 52 | case STRING: 53 | cell.setCellValue((String) map.get("value")); 54 | case FORMULA: 55 | break; 56 | case BLANK: 57 | break; 58 | case BOOLEAN: 59 | cell.setCellValue((boolean) map.get("value")); 60 | case ERROR: 61 | break; 62 | } 63 | } 64 | } 65 | } 66 | 67 | } 68 | 69 | private static Map copyCell(Cell cell) { 70 | Map map = new HashMap<>(); 71 | map.put("cellType", cell.getCellType()); 72 | map.put("isDate", CellType.NUMERIC == cell.getCellType() && DateUtil.isCellDateFormatted(cell)); 73 | map.put("value", getValue(cell)); 74 | map.put("cellStyle", cell.getCellStyle()); 75 | return map; 76 | } 77 | 78 | private static Object getValue(Cell cell) { 79 | if (CellType.NUMERIC == cell.getCellType() && DateUtil.isCellDateFormatted(cell)) { 80 | return cell.getDateCellValue(); 81 | } 82 | switch (cell.getCellType()) { 83 | case _NONE: 84 | return null; 85 | case NUMERIC: 86 | return cell.getNumericCellValue(); 87 | case STRING: 88 | return cell.getStringCellValue(); 89 | case FORMULA: 90 | return cell.getCellFormula(); 91 | case BLANK: 92 | break; 93 | case BOOLEAN: 94 | return cell.getBooleanCellValue(); 95 | case ERROR: 96 | break; 97 | } 98 | return null; 99 | } 100 | 101 | 102 | } 103 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/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 cn.afterturn.easypoi.excel.export.styler; 17 | 18 | import org.apache.poi.ss.usermodel.*; 19 | import org.apache.poi.util.Removal; 20 | 21 | /** 22 | * 带有样式的导出服务 23 | * @author JueYue 24 | * 2015年1月9日 下午4:54:15 25 | */ 26 | @Deprecated 27 | @Removal( 28 | version = "4.2" 29 | ) 30 | public class ExcelExportStylerColorImpl extends AbstractExcelExportStyler 31 | implements IExcelExportStyler { 32 | 33 | public ExcelExportStylerColorImpl(Workbook workbook) { 34 | super.createStyles(workbook); 35 | } 36 | 37 | @Override 38 | public CellStyle getHeaderStyle(short headerColor) { 39 | CellStyle titleStyle = workbook.createCellStyle(); 40 | Font font = workbook.createFont(); 41 | font.setFontHeightInPoints((short) 24); 42 | titleStyle.setFont(font); 43 | titleStyle.setFillForegroundColor(headerColor); 44 | titleStyle.setAlignment(HorizontalAlignment.CENTER); 45 | titleStyle.setVerticalAlignment(VerticalAlignment.CENTER); 46 | return titleStyle; 47 | } 48 | 49 | @Override 50 | public CellStyle stringNoneStyle(Workbook workbook, boolean isWarp) { 51 | CellStyle style = workbook.createCellStyle(); 52 | style.setBorderLeft(BorderStyle.THIN); 53 | style.setBorderRight(BorderStyle.THIN); 54 | style.setBorderBottom(BorderStyle.THIN); 55 | style.setBorderTop(BorderStyle.THIN); 56 | style.setAlignment(HorizontalAlignment.CENTER); 57 | style.setVerticalAlignment(VerticalAlignment.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.setFillForegroundColor(color); 69 | titleStyle.setAlignment(HorizontalAlignment.CENTER); 70 | titleStyle.setVerticalAlignment(VerticalAlignment.CENTER); 71 | titleStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); 72 | titleStyle.setWrapText(true); 73 | return titleStyle; 74 | } 75 | 76 | @Override 77 | public CellStyle stringSeptailStyle(Workbook workbook, boolean isWarp) { 78 | CellStyle style = workbook.createCellStyle(); 79 | style.setBorderLeft(BorderStyle.THIN); 80 | style.setBorderRight(BorderStyle.THIN); 81 | style.setBorderBottom(BorderStyle.THIN); 82 | style.setBorderTop(BorderStyle.THIN); 83 | style.setFillForegroundColor((short) 41); 84 | style.setFillPattern(FillPatternType.SOLID_FOREGROUND); 85 | style.setAlignment(HorizontalAlignment.CENTER); 86 | style.setVerticalAlignment(VerticalAlignment.CENTER); 87 | style.setDataFormat(STRING_FORMAT); 88 | if (isWarp) { 89 | style.setWrapText(true); 90 | } 91 | return style; 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /easypoi-base/src/main/java/cn/afterturn/easypoi/pdf/entity/PdfExportParams.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 cn.afterturn.easypoi.pdf.entity; 17 | 18 | import cn.afterturn.easypoi.excel.entity.ExcelBaseParams; 19 | import cn.afterturn.easypoi.pdf.styler.IPdfExportStyler; 20 | 21 | /** 22 | * PDF 导出参数设置 23 | * @author JueYue 24 | * 2016年1月8日 下午1:52:06 25 | */ 26 | public class PdfExportParams extends ExcelBaseParams { 27 | 28 | /** 29 | * 表格名称 30 | */ 31 | private String title; 32 | 33 | /** 34 | * 表格名称 35 | */ 36 | private short titleHeight = 30; 37 | 38 | /** 39 | * 第二行名称 40 | */ 41 | private String secondTitle; 42 | 43 | /** 44 | * 表格名称 45 | */ 46 | private short secondTitleHeight = 25; 47 | /** 48 | * 过滤的属性 49 | */ 50 | private String[] exclusions; 51 | /** 52 | * 是否添加需要需要 53 | */ 54 | private boolean addIndex; 55 | /** 56 | * 是否添加需要需要 57 | */ 58 | private String indexName = "序号"; 59 | 60 | private IPdfExportStyler styler; 61 | 62 | public PdfExportParams() { 63 | 64 | } 65 | 66 | public PdfExportParams(String title) { 67 | this.title = title; 68 | } 69 | 70 | public PdfExportParams(String title, String secondTitle) { 71 | this.title = title; 72 | this.secondTitle = secondTitle; 73 | } 74 | 75 | public String getTitle() { 76 | return title; 77 | } 78 | 79 | public void setTitle(String title) { 80 | this.title = title; 81 | } 82 | 83 | public short getTitleHeight() { 84 | return titleHeight; 85 | } 86 | 87 | public void setTitleHeight(short titleHeight) { 88 | this.titleHeight = titleHeight; 89 | } 90 | 91 | public String getSecondTitle() { 92 | return secondTitle; 93 | } 94 | 95 | public void setSecondTitle(String secondTitle) { 96 | this.secondTitle = secondTitle; 97 | } 98 | 99 | public short getSecondTitleHeight() { 100 | return secondTitleHeight; 101 | } 102 | 103 | public void setSecondTitleHeight(short secondTitleHeight) { 104 | this.secondTitleHeight = secondTitleHeight; 105 | } 106 | 107 | public String[] getExclusions() { 108 | return exclusions; 109 | } 110 | 111 | public void setExclusions(String[] exclusions) { 112 | this.exclusions = exclusions; 113 | } 114 | 115 | public boolean isAddIndex() { 116 | return addIndex; 117 | } 118 | 119 | public void setAddIndex(boolean addIndex) { 120 | this.addIndex = addIndex; 121 | } 122 | 123 | public String getIndexName() { 124 | return indexName; 125 | } 126 | 127 | public void setIndexName(String indexName) { 128 | this.indexName = indexName; 129 | } 130 | 131 | public IPdfExportStyler getStyler() { 132 | return styler; 133 | } 134 | 135 | public void setStyler(IPdfExportStyler styler) { 136 | this.styler = styler; 137 | } 138 | 139 | } 140 | --------------------------------------------------------------------------------