@@ -58,17 +58,17 @@ https://oss.sonatype.org/content/repositories/snapshots/ | |||
<dependency> | |||
<groupId>org.jeecg</groupId> | |||
<artifactId>easypoi-base</artifactId> | |||
<version>2.1.6</version> | |||
<version>2.3.0</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.jeecg</groupId> | |||
<artifactId>easypoi-web</artifactId> | |||
<version>2.1.6</version> | |||
<version>2.3.0</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.jeecg</groupId> | |||
<artifactId>easypoi-annotation</artifactId> | |||
<version>2.1.6</version> | |||
<version>2.3.0</version> | |||
</dependency> | |||
``` | |||
@@ -173,7 +173,17 @@ word和sax读取的时候才使用,就不是必须的了,请手动引用,JSR303 | |||
-------------------------- | |||
版本修改 | |||
-------------------------- | |||
- 2.3.0 修复bug,推荐更新 | |||
- 提供的PDF基础的Excel导出支持 | |||
- 提供了Excel Charts的导出支持 | |||
- 升级了POI | |||
- 提供了Word换行支持 | |||
- 图片提供统一缓存 | |||
- 增加Cell取值工具,自动分辨合并单元格和独立单元格 | |||
- 修复合并单元格,获取cell改为递归,之前判断有问题 | |||
- 修改了下,el表达式的==判断,给fe加上了样式自定义方法 | |||
- 修复if(),单字段的判断 | |||
- 修复其他一些bug | |||
- 2.1.6 校验规则不向下兼容,升级请自行考虑 | |||
- 其实不想升的,不过有必要的bug要修复,所以就先生上来吧 | |||
- 升级交易为hibernate校验,hibernate的maven自己配置可选 | |||
@@ -364,17 +374,14 @@ EasyPoi导出实例 | |||
8.Excel导入校验,过滤不符合规则的数据,追加错误信息到Excel,提供常用的校验规则,已经通用的校验接口 | |||
```Java | |||
/** | |||
* Email校验 | |||
*/ | |||
@Excel(name = "Email", width = 25) | |||
@ExcelVerify(isEmail = true, notNull = true) | |||
private String email; | |||
@Max(value = 15,message = "max 最大值不能超过15") | |||
private int email; | |||
/** | |||
* 手机号校验 | |||
* 手机号 | |||
*/ | |||
@Excel(name = "Mobile", width = 20) | |||
@ExcelVerify(isMobile = true, notNull = true) | |||
@NotNull | |||
private String mobile; | |||
ExcelImportResult<ExcelVerifyEntity> result = ExcelImportUtil.importExcelVerify(new File( | |||
@@ -25,6 +25,7 @@ import java.util.Iterator; | |||
import java.util.List; | |||
import org.apache.commons.lang3.StringUtils; | |||
import org.apache.poi.util.IOUtils; | |||
import org.jeecgframework.poi.cache.ImageCache; | |||
import org.jeecgframework.poi.excel.annotation.ExcelTarget; | |||
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; | |||
@@ -95,7 +96,11 @@ public class PdfExportServer extends ExportBase { | |||
} catch (Exception e) { | |||
LOGGER.error(e.getMessage(), e); | |||
} finally { | |||
document.close(); | |||
try { | |||
document.close(); | |||
} catch (Exception e) { | |||
//可能之前已经关闭过了 | |||
} | |||
} | |||
return document; | |||
} | |||
@@ -129,6 +134,8 @@ public class PdfExportServer extends ExportBase { | |||
LOGGER.error(e.getMessage(), e); | |||
} catch (Exception e) { | |||
LOGGER.error(e.getMessage(), e); | |||
} finally { | |||
document.close(); | |||
} | |||
return document; | |||
} | |||
@@ -4,6 +4,8 @@ dependencies { | |||
compile group: 'org.springframework', name: 'spring-web', version:'3.1.1.RELEASE' | |||
compile group: 'org.springframework', name: 'spring-webmvc', version:'3.1.1.RELEASE' | |||
compile group: 'org.springframework', name: 'spring-core', version:'3.1.1.RELEASE' | |||
compile group: 'org.springframework', name: 'spring-core', version:'3.1.1.RELEASE' | |||
compile group: 'com.itextpdf', name: 'itextpdf', version:'5.5.6' | |||
compile project(':easypoi-base') | |||
compile(group: 'javax.servlet', name: 'servlet-api', version:'2.5') { | |||
/* This dependency was originally in the Maven provided scope, but the project was not of type war. | |||
@@ -28,6 +28,13 @@ | |||
<scope>provided</scope> | |||
</dependency> | |||
<!-- PDF --> | |||
<dependency> | |||
<groupId>com.itextpdf</groupId> | |||
<artifactId>itextpdf</artifactId> | |||
<optional>true</optional> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.jeecg</groupId> | |||
<artifactId>easypoi-base</artifactId> | |||
@@ -0,0 +1,33 @@ | |||
/** | |||
* Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
package org.jeecgframework.poi.excel.entity.vo; | |||
public interface PDFTemplateConstants extends BasePOIConstants { | |||
/** | |||
*/ | |||
public final static String PDF_TEMPLATE_VIEW = "pdfTemplateView"; | |||
/** | |||
* Entity List | |||
*/ | |||
public final static String ENTITY_LIST = "EntityList"; | |||
/** | |||
* 数据列表 | |||
*/ | |||
public final static String DATA_LIST = "dataList"; | |||
} |
@@ -25,7 +25,6 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument; | |||
import org.jeecgframework.poi.excel.entity.vo.TemplateWordConstants; | |||
import org.jeecgframework.poi.word.WordExportUtil; | |||
import org.springframework.stereotype.Controller; | |||
import org.springframework.web.servlet.view.AbstractView; | |||
/** | |||
* Word模板视图 | |||
@@ -35,7 +34,7 @@ import org.springframework.web.servlet.view.AbstractView; | |||
*/ | |||
@SuppressWarnings("unchecked") | |||
@Controller(TemplateWordConstants.JEECG_TEMPLATE_WORD_VIEW) | |||
public class JeecgTemplateWordView extends AbstractView { | |||
public class JeecgTemplateWordView extends PoiBaseView { | |||
private static final String CONTENT_TYPE = "application/msword"; | |||
@@ -43,11 +42,6 @@ public class JeecgTemplateWordView extends AbstractView { | |||
setContentType(CONTENT_TYPE); | |||
} | |||
public boolean isIE(HttpServletRequest request) { | |||
return (request.getHeader("USER-AGENT").toLowerCase().indexOf("msie") > 0 || request | |||
.getHeader("USER-AGENT").toLowerCase().indexOf("rv:11.0") > 0) ? true : false; | |||
} | |||
@Override | |||
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, | |||
HttpServletResponse response) throws Exception { | |||
@@ -18,7 +18,6 @@ package org.jeecgframework.poi.excel.view; | |||
import java.util.List; | |||
import java.util.Map; | |||
import javax.annotation.Resource; | |||
import javax.servlet.ServletOutputStream; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
@@ -15,16 +15,12 @@ | |||
*/ | |||
package org.jeecgframework.poi.excel.view; | |||
import javax.servlet.http.HttpServletRequest; | |||
import org.springframework.web.servlet.view.AbstractView; | |||
/** | |||
* 基础抽象Excel View | |||
* @author JueYue | |||
* @date 2015年2月28日 下午1:41:05 | |||
*/ | |||
public abstract class MiniAbstractExcelView extends AbstractView { | |||
public abstract class MiniAbstractExcelView extends PoiBaseView { | |||
private static final String CONTENT_TYPE = "application/vnd.ms-excel"; | |||
@@ -35,9 +31,4 @@ public abstract class MiniAbstractExcelView extends AbstractView { | |||
setContentType(CONTENT_TYPE); | |||
} | |||
protected boolean isIE(HttpServletRequest request) { | |||
return (request.getHeader("USER-AGENT").toLowerCase().indexOf("msie") > 0 || request | |||
.getHeader("USER-AGENT").toLowerCase().indexOf("rv:11.0") > 0) ? true : false; | |||
} | |||
} |
@@ -0,0 +1,81 @@ | |||
/** | |||
* Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
package org.jeecgframework.poi.excel.view; | |||
import java.io.ByteArrayOutputStream; | |||
import java.util.Collection; | |||
import java.util.List; | |||
import java.util.Map; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
import org.apache.commons.lang3.StringUtils; | |||
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; | |||
import org.jeecgframework.poi.excel.entity.vo.PDFTemplateConstants; | |||
import org.jeecgframework.poi.pdf.PdfExportUtil; | |||
import org.jeecgframework.poi.pdf.entity.PdfExportParams; | |||
import org.springframework.stereotype.Controller; | |||
/** | |||
* PDF 导出 View | |||
* @author JueYue | |||
* @date 2016年1月19日 上午10:43:02 | |||
*/ | |||
@Controller(PDFTemplateConstants.PDF_TEMPLATE_VIEW) | |||
public class PDFTemplateView extends PoiBaseView { | |||
public PDFTemplateView() { | |||
setContentType("application/pdf"); | |||
} | |||
@Override | |||
protected boolean generatesDownloadContent() { | |||
return true; | |||
} | |||
@Override | |||
@SuppressWarnings("unchecked") | |||
protected final void renderMergedOutputModel(Map<String, Object> model, | |||
HttpServletRequest request, | |||
HttpServletResponse response) throws Exception { | |||
String fileName = "临时文件"; | |||
ByteArrayOutputStream baos = createTemporaryOutputStream(); | |||
PdfExportParams entity = (PdfExportParams) model.get(PDFTemplateConstants.PARAMS); | |||
Class<?> pojoClass = (Class<?>) model.get(PDFTemplateConstants.CLASS); | |||
Collection<?> dataSet = (Collection<?>) model.get(PDFTemplateConstants.DATA_LIST); | |||
List<ExcelExportEntity> entityList = (List<ExcelExportEntity>) model | |||
.get(PDFTemplateConstants.ENTITY_LIST); | |||
if (entityList == null) { | |||
PdfExportUtil.exportPdf(entity, pojoClass, dataSet, baos); | |||
} else { | |||
PdfExportUtil.exportPdf(entity, entityList, (Collection<? extends Map<?, ?>>) dataSet, | |||
baos); | |||
} | |||
String userFileName = (String) model.get(PDFTemplateConstants.FILE_NAME); | |||
if (StringUtils.isNoneBlank(userFileName)) { | |||
fileName = userFileName; | |||
} | |||
if (isIE(request)) { | |||
fileName = java.net.URLEncoder.encode(fileName, "UTF8"); | |||
} else { | |||
fileName = new String(fileName.getBytes("UTF-8"), "ISO-8859-1"); | |||
} | |||
response.setHeader("content-disposition", "attachment;filename=" + fileName + ".pdf"); | |||
writeToResponse(response, baos); | |||
} | |||
} |
@@ -0,0 +1,35 @@ | |||
/** | |||
* Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
package org.jeecgframework.poi.excel.view; | |||
import javax.servlet.http.HttpServletRequest; | |||
import org.springframework.web.servlet.view.AbstractView; | |||
/** | |||
* 提供一些通用结构 | |||
*/ | |||
public abstract class PoiBaseView extends AbstractView { | |||
protected boolean isIE(HttpServletRequest request) { | |||
return (request.getHeader("USER-AGENT").toLowerCase().indexOf("msie") > 0 | |||
|| request.getHeader("USER-AGENT").toLowerCase().indexOf("rv:11.0") > 0 | |||
|| request.getHeader("USER-AGENT").toLowerCase().indexOf("edge") > 0) ? true | |||
: false; | |||
} | |||
} |