| @@ -1 +1 @@ | |||
| cmd /k mvn clean deploy -DskipTest | |||
| cmd /k mvn clean deploy -D skipTest | |||
| @@ -6,8 +6,9 @@ | |||
| <attribute name="maven.pomderived" value="true"/> | |||
| </attributes> | |||
| </classpathentry> | |||
| <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | |||
| <classpathentry kind="src" output="target/test-classes" path="src/test/java"> | |||
| <attributes> | |||
| <attribute name="optional" value="true"/> | |||
| <attribute name="maven.pomderived" value="true"/> | |||
| </attributes> | |||
| </classpathentry> | |||
| @@ -16,9 +17,8 @@ | |||
| <attribute name="maven.pomderived" value="true"/> | |||
| </attributes> | |||
| </classpathentry> | |||
| <classpathentry kind="src" output="target/test-classes" path="src/test/java"> | |||
| <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | |||
| <attributes> | |||
| <attribute name="optional" value="true"/> | |||
| <attribute name="maven.pomderived" value="true"/> | |||
| </attributes> | |||
| </classpathentry> | |||
| @@ -4,7 +4,7 @@ | |||
| <parent> | |||
| <groupId>org.jeecgframework</groupId> | |||
| <artifactId>easypoi</artifactId> | |||
| <version>2.0.2</version> | |||
| <version>2.0.6-SNAPSHOT</version> | |||
| </parent> | |||
| <artifactId>easypoi-base</artifactId> | |||
| <dependencies> | |||
| @@ -8,6 +8,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook; | |||
| import org.apache.poi.ss.usermodel.*; | |||
| import org.jeecgframework.poi.excel.entity.ExportParams; | |||
| import org.jeecgframework.poi.excel.entity.TemplateExportParams; | |||
| import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; | |||
| import org.jeecgframework.poi.excel.export.ExcelExportServer; | |||
| import org.jeecgframework.poi.excel.export.template.ExcelExportOfTemplateUtil; | |||
| @@ -54,6 +55,20 @@ public final class ExcelExportUtil { | |||
| new ExcelExportServer().createSheet(workbook, entity, pojoClass, dataSet); | |||
| return workbook; | |||
| } | |||
| /** | |||
| * @param entity | |||
| * 表格标题属性 | |||
| * @param pojoClass | |||
| * Excel对象Class | |||
| * @param dataSet | |||
| * Excel对象数据List | |||
| */ | |||
| public static HSSFWorkbook exportExcel(ExportParams entity, | |||
| List<ExcelExportEntity> entityList, Collection<? extends Map<?,?>> dataSet) { | |||
| HSSFWorkbook workbook = new HSSFWorkbook(); | |||
| new ExcelExportServer().createSheetForMap(workbook, entity, entityList, dataSet); | |||
| return workbook; | |||
| } | |||
| /** | |||
| * 导出文件通过模板解析 | |||
| @@ -49,6 +49,10 @@ public class ExportParams extends ExcelBaseParams { | |||
| * 过滤的属性 | |||
| */ | |||
| private String[] exclusions; | |||
| /** | |||
| * 是否添加需要需要 | |||
| */ | |||
| private boolean addIndex; | |||
| /** | |||
| * 表头颜色 | |||
| */ | |||
| @@ -122,4 +126,12 @@ public class ExportParams extends ExcelBaseParams { | |||
| public void setSecondTitleHeight(short secondTitleHeight) { | |||
| this.secondTitleHeight = secondTitleHeight; | |||
| } | |||
| public boolean isAddIndex() { | |||
| return addIndex; | |||
| } | |||
| public void setAddIndex(boolean addIndex) { | |||
| this.addIndex = addIndex; | |||
| } | |||
| } | |||
| @@ -11,11 +11,11 @@ public class ExcelBaseEntity { | |||
| /** | |||
| * 对应name | |||
| */ | |||
| private String name; | |||
| protected String name; | |||
| /** | |||
| * 对应type | |||
| */ | |||
| private int type; | |||
| private int type = 1; | |||
| /** | |||
| * 数据库格式 | |||
| */ | |||
| @@ -10,16 +10,41 @@ import java.util.List; | |||
| */ | |||
| public class ExcelExportEntity extends ExcelBaseEntity { | |||
| private int width; | |||
| private int height; | |||
| public ExcelExportEntity() { | |||
| } | |||
| public ExcelExportEntity(String name) { | |||
| super.name = name; | |||
| } | |||
| public ExcelExportEntity(String name, Object key) { | |||
| super.name = name; | |||
| this.key = key; | |||
| } | |||
| public ExcelExportEntity(String name, Object key, int width) { | |||
| super.name = name; | |||
| this.width = width; | |||
| this.key = key; | |||
| } | |||
| /** | |||
| * 如果是MAP导出,这个是map的key | |||
| */ | |||
| private Object key; | |||
| private int width = 10; | |||
| private int height = 10; | |||
| /** | |||
| * 图片的类型,1是文件,2是数据库 | |||
| */ | |||
| private int exportImageType; | |||
| private int exportImageType = 0; | |||
| /** | |||
| * 排序顺序 | |||
| */ | |||
| private int orderNum; | |||
| private int orderNum = 0; | |||
| /** | |||
| * 是否支持换行 | |||
| */ | |||
| @@ -123,4 +148,12 @@ public class ExcelExportEntity extends ExcelBaseEntity { | |||
| this.mergeVertical = mergeVertical; | |||
| } | |||
| public Object getKey() { | |||
| return key; | |||
| } | |||
| public void setKey(Object key) { | |||
| this.key = key; | |||
| } | |||
| } | |||
| @@ -11,5 +11,7 @@ public interface PoiBaseConstants { | |||
| public static String SET = "set"; | |||
| public static String IS = "is"; | |||
| public static String IS_ADD_INDEX = "isAddIndex"; | |||
| } | |||
| @@ -22,6 +22,7 @@ import org.apache.poi.ss.util.CellRangeAddress; | |||
| import org.jeecgframework.poi.excel.annotation.ExcelTarget; | |||
| import org.jeecgframework.poi.excel.entity.ExportParams; | |||
| import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; | |||
| import org.jeecgframework.poi.excel.entity.vo.PoiBaseConstants; | |||
| import org.jeecgframework.poi.excel.export.base.ExcelExportBase; | |||
| import org.jeecgframework.poi.exception.excel.ExcelExportException; | |||
| import org.jeecgframework.poi.exception.excel.enums.ExcelExportEnum; | |||
| @@ -36,8 +37,9 @@ import org.slf4j.LoggerFactory; | |||
| * @date 2014年6月17日 下午5:30:54 | |||
| */ | |||
| public class ExcelExportServer extends ExcelExportBase { | |||
| private final static Logger logger = LoggerFactory.getLogger(ExcelExportServer.class); | |||
| private final static Logger logger = LoggerFactory | |||
| .getLogger(ExcelExportServer.class); | |||
| private static final short cellFormat = HSSFDataFormat | |||
| .getBuiltinFormat("TEXT"); | |||
| @@ -47,8 +49,8 @@ public class ExcelExportServer extends ExcelExportBase { | |||
| public void createSheet(HSSFWorkbook workbook, ExportParams entity, | |||
| Class<?> pojoClass, Collection<?> dataSet) { | |||
| if(logger.isDebugEnabled()){ | |||
| logger.debug("Excel export start ,class is {}",pojoClass); | |||
| if (logger.isDebugEnabled()) { | |||
| logger.debug("Excel export start ,class is {}", pojoClass); | |||
| } | |||
| if (workbook == null || entity == null || pojoClass == null | |||
| || dataSet == null) { | |||
| @@ -71,6 +73,9 @@ public class ExcelExportServer extends ExcelExportBase { | |||
| Map<String, HSSFCellStyle> styles = createStyles(workbook); | |||
| Drawing patriarch = sheet.createDrawingPatriarch(); | |||
| List<ExcelExportEntity> excelParams = new ArrayList<ExcelExportEntity>(); | |||
| if (entity.isAddIndex()) { | |||
| excelParams.add(indexExcelEntity()); | |||
| } | |||
| // 得到所有字段 | |||
| Field fileds[] = POIPublicUtil.getClassFields(pojoClass); | |||
| ExcelTarget etarget = pojoClass.getAnnotation(ExcelTarget.class); | |||
| @@ -83,7 +88,7 @@ public class ExcelExportServer extends ExcelExportBase { | |||
| int titleHeight = index; | |||
| setCellWith(excelParams, sheet); | |||
| short rowHeight = getRowHeight(excelParams); | |||
| setCurrentIndex(1); | |||
| Iterator<?> its = dataSet.iterator(); | |||
| List<Object> tempList = new ArrayList<Object>(); | |||
| while (its.hasNext()) { | |||
| @@ -107,12 +112,21 @@ public class ExcelExportServer extends ExcelExportBase { | |||
| } | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| logger.error(e.getMessage(),e.fillInStackTrace()); | |||
| throw new ExcelExportException(ExcelExportEnum.EXPORT_ERROR, | |||
| e.getCause()); | |||
| } | |||
| } | |||
| private ExcelExportEntity indexExcelEntity() { | |||
| ExcelExportEntity entity = new ExcelExportEntity(); | |||
| entity.setOrderNum(0); | |||
| entity.setName("序号"); | |||
| entity.setWidth(10); | |||
| entity.setFormat(PoiBaseConstants.IS_ADD_INDEX); | |||
| return entity; | |||
| } | |||
| private int createHeaderAndTitle(ExportParams entity, Sheet sheet, | |||
| HSSFWorkbook workbook, List<ExcelExportEntity> excelParams) { | |||
| int rows = 0, feildWidth = getFieldWidth(excelParams); | |||
| @@ -298,4 +312,69 @@ public class ExcelExportServer extends ExcelExportBase { | |||
| return map.get("two"); | |||
| } | |||
| public void createSheetForMap(HSSFWorkbook workbook, ExportParams entity, | |||
| List<ExcelExportEntity> entityList, | |||
| Collection<? extends Map<?, ?>> dataSet) { | |||
| if (workbook == null || entity == null || entityList == null | |||
| || dataSet == null) { | |||
| throw new ExcelExportException(ExcelExportEnum.PARAMETER_ERROR); | |||
| } | |||
| Sheet sheet = null; | |||
| try { | |||
| sheet = workbook.createSheet(entity.getSheetName()); | |||
| } catch (Exception e) { | |||
| // 重复遍历,出现了重名现象,创建非指定的名称Sheet | |||
| sheet = workbook.createSheet(); | |||
| } | |||
| try { | |||
| dataHanlder = entity.getDataHanlder(); | |||
| if (dataHanlder != null) { | |||
| needHanlderList = Arrays.asList(dataHanlder | |||
| .getNeedHandlerFields()); | |||
| } | |||
| // 创建表格属性 | |||
| Map<String, HSSFCellStyle> styles = createStyles(workbook); | |||
| Drawing patriarch = sheet.createDrawingPatriarch(); | |||
| List<ExcelExportEntity> excelParams = new ArrayList<ExcelExportEntity>(); | |||
| if (entity.isAddIndex()) { | |||
| excelParams.add(indexExcelEntity()); | |||
| } | |||
| excelParams.addAll(entityList); | |||
| sortAllParams(excelParams); | |||
| int index = createHeaderAndTitle(entity, sheet, workbook, | |||
| excelParams); | |||
| int titleHeight = index; | |||
| setCellWith(excelParams, sheet); | |||
| short rowHeight = getRowHeight(excelParams); | |||
| setCurrentIndex(1); | |||
| Iterator<?> its = dataSet.iterator(); | |||
| List<Object> tempList = new ArrayList<Object>(); | |||
| while (its.hasNext()) { | |||
| Object t = its.next(); | |||
| index += createCells(patriarch, index, t, excelParams, sheet, | |||
| workbook, styles, rowHeight); | |||
| tempList.add(t); | |||
| if (index >= MAX_NUM) | |||
| break; | |||
| } | |||
| mergeCells(sheet, excelParams, titleHeight); | |||
| its = dataSet.iterator(); | |||
| for (int i = 0, le = tempList.size(); i < le; i++) { | |||
| its.next(); | |||
| its.remove(); | |||
| } | |||
| // 发现还有剩余list 继续循环创建Sheet | |||
| if (dataSet.size() > 0) { | |||
| createSheetForMap(workbook, entity, entityList, dataSet); | |||
| } | |||
| } catch (Exception e) { | |||
| e.printStackTrace(); | |||
| logger.error(e.getMessage(),e.fillInStackTrace()); | |||
| throw new ExcelExportException(ExcelExportEnum.EXPORT_ERROR, | |||
| e.getCause()); | |||
| } | |||
| } | |||
| } | |||
| @@ -28,6 +28,7 @@ import org.apache.poi.ss.usermodel.Workbook; | |||
| import org.apache.poi.ss.util.CellRangeAddress; | |||
| import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; | |||
| import org.jeecgframework.poi.excel.entity.params.MergeEntity; | |||
| import org.jeecgframework.poi.excel.entity.vo.PoiBaseConstants; | |||
| import org.jeecgframework.poi.util.POIPublicUtil; | |||
| /** | |||
| @@ -38,6 +39,8 @@ import org.jeecgframework.poi.util.POIPublicUtil; | |||
| */ | |||
| public abstract class ExcelExportBase extends ExportBase { | |||
| private int currentIndex = 0; | |||
| /** | |||
| * 合并单元格 | |||
| * | |||
| @@ -213,7 +216,9 @@ public abstract class ExcelExportBase extends ExportBase { | |||
| Row row = sheet.createRow(index); | |||
| row.setHeight(rowHeight); | |||
| int maxHeight = 1, cellNum = 0; | |||
| for (int k = 0, paramSize = excelParams.size(); k < paramSize; k++) { | |||
| int indexKey = createIndexCell(row, styles, index, excelParams.get(0)); | |||
| cellNum += indexKey; | |||
| for (int k = indexKey, paramSize = excelParams.size(); k < paramSize; k++) { | |||
| entity = excelParams.get(k); | |||
| if (entity.getList() != null) { | |||
| Collection<?> list = (Collection<?>) entity.getMethod().invoke( | |||
| @@ -246,7 +251,7 @@ public abstract class ExcelExportBase extends ExportBase { | |||
| } | |||
| // 合并需要合并的单元格 | |||
| cellNum = 0; | |||
| for (int k = 0, paramSize = excelParams.size(); k < paramSize; k++) { | |||
| for (int k = indexKey, paramSize = excelParams.size(); k < paramSize; k++) { | |||
| entity = excelParams.get(k); | |||
| if (entity.getList() != null) { | |||
| cellNum += entity.getList().size(); | |||
| @@ -260,6 +265,20 @@ public abstract class ExcelExportBase extends ExportBase { | |||
| } | |||
| private int createIndexCell(Row row, Map<String, HSSFCellStyle> styles, | |||
| int index, ExcelExportEntity excelExportEntity) { | |||
| if (excelExportEntity.getName().equals("序号") | |||
| && excelExportEntity.getFormat().equals( | |||
| PoiBaseConstants.IS_ADD_INDEX)) { | |||
| createStringCell(row, 0, currentIndex + "", | |||
| index % 2 == 0 ? getStyles(styles, false, false) | |||
| : getStyles(styles, true, false), null); | |||
| currentIndex = currentIndex + 1; | |||
| return 1; | |||
| } | |||
| return 0; | |||
| } | |||
| public CellStyle getStyles(Map<String, HSSFCellStyle> styles, boolean b, | |||
| boolean wrap) { | |||
| return null; | |||
| @@ -417,4 +436,8 @@ public abstract class ExcelExportBase extends ExportBase { | |||
| return length; | |||
| } | |||
| public void setCurrentIndex(int currentIndex) { | |||
| this.currentIndex = currentIndex; | |||
| } | |||
| } | |||
| @@ -9,6 +9,7 @@ import java.util.Arrays; | |||
| import java.util.Collections; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import org.apache.commons.lang.StringUtils; | |||
| import org.jeecgframework.poi.excel.annotation.Excel; | |||
| @@ -26,7 +27,7 @@ import org.jeecgframework.poi.util.POIPublicUtil; | |||
| * @date 2014年8月9日 下午11:01:32 | |||
| */ | |||
| public class ExportBase { | |||
| protected IExcelDataHandler dataHanlder; | |||
| protected List<String> needHanlderList; | |||
| @@ -54,7 +55,11 @@ public class ExportBase { | |||
| targetId)) { | |||
| continue; | |||
| } | |||
| if (POIPublicUtil.isCollection(field.getType())) { | |||
| // 首先判断Excel 可能一下特殊数据用户回自定义处理 | |||
| if (field.getAnnotation(Excel.class) != null) { | |||
| excelParams.add(createExcelExportEntity(field, targetId, | |||
| pojoClass, getMethods)); | |||
| } else if (POIPublicUtil.isCollection(field.getType())) { | |||
| ExcelCollection excel = field | |||
| .getAnnotation(ExcelCollection.class); | |||
| ParameterizedType pt = (ParameterizedType) field | |||
| @@ -73,9 +78,6 @@ public class ExportBase { | |||
| pojoClass)); | |||
| excelEntity.setList(list); | |||
| excelParams.add(excelEntity); | |||
| } else if (POIPublicUtil.isJavaClass(field)) { | |||
| excelParams.add(createExcelExportEntity(field, targetId, | |||
| pojoClass, getMethods)); | |||
| } else { | |||
| List<Method> newMethods = new ArrayList<Method>(); | |||
| if (getMethods != null) { | |||
| @@ -108,7 +110,12 @@ public class ExportBase { | |||
| throws Exception { | |||
| Excel excel = field.getAnnotation(Excel.class); | |||
| ExcelExportEntity excelEntity = new ExcelExportEntity(); | |||
| excelEntity.setType(excel.type()); | |||
| try { | |||
| excelEntity.setType(excel.type()); | |||
| } catch (Exception e) { | |||
| // TODO Auto-generated catch block | |||
| e.printStackTrace(); | |||
| } | |||
| getExcelField(targetId, field, excelEntity, excel, pojoClass); | |||
| if (getMethods != null) { | |||
| List<Method> newMethods = new ArrayList<Method>(); | |||
| @@ -203,8 +210,10 @@ public class ExportBase { | |||
| String fieldname = field.getName(); | |||
| excelEntity.setMethod(POIPublicUtil.getMethod(fieldname, pojoClass)); | |||
| } | |||
| /** | |||
| * 根据注解获取行高 | |||
| * | |||
| * @param excelParams | |||
| * @return | |||
| */ | |||
| @@ -223,7 +232,6 @@ public class ExportBase { | |||
| } | |||
| return (short) (maxHeight * 50); | |||
| } | |||
| /** | |||
| * 对字段根据用户设置排序 | |||
| @@ -236,7 +244,7 @@ public class ExportBase { | |||
| } | |||
| } | |||
| } | |||
| /** | |||
| * 获取填如这个cell的值,提供一些附加功能 | |||
| * | |||
| @@ -247,9 +255,14 @@ public class ExportBase { | |||
| */ | |||
| public Object getCellValue(ExcelExportEntity entity, Object obj) | |||
| throws Exception { | |||
| Object value = entity.getMethods() != null ? getFieldBySomeMethod( | |||
| entity.getMethods(), obj) : entity.getMethod().invoke(obj, | |||
| new Object[] {}); | |||
| Object value; | |||
| if (obj instanceof Map) { | |||
| return ((Map<?, ?>) obj).get(entity.getKey()); | |||
| } else { | |||
| value = entity.getMethods() != null ? getFieldBySomeMethod( | |||
| entity.getMethods(), obj) : entity.getMethod().invoke(obj, | |||
| new Object[] {}); | |||
| } | |||
| if (needHanlderList != null | |||
| && needHanlderList.contains(entity.getName())) { | |||
| value = dataHanlder.exportHandler(obj, entity.getName(), value); | |||
| @@ -290,7 +303,7 @@ public class ExportBase { | |||
| } | |||
| return value; | |||
| } | |||
| /** | |||
| * 多个反射获取值 | |||
| * | |||
| @@ -32,6 +32,7 @@ import org.jeecgframework.poi.util.POIPublicUtil; | |||
| * @version 1.0 | |||
| */ | |||
| public final class ExcelExportOfTemplateUtil extends ExcelExportBase { | |||
| public Workbook createExcleByTemplate(TemplateExportParams params, | |||
| Class<?> pojoClass, Collection<?> dataSet, Map<String, Object> map) { | |||
| @@ -44,19 +45,13 @@ public final class ExcelExportOfTemplateUtil extends ExcelExportBase { | |||
| // step 2. 判断模板的Excel类型,解析模板 | |||
| try { | |||
| wb = getCloneWorkBook(params); | |||
| // step 3. 删除其他的sheet | |||
| for (int i = wb.getNumberOfSheets() - 1; i >= 0; i--) { | |||
| if (i != params.getSheetNum()) { | |||
| wb.removeSheetAt(i); | |||
| } | |||
| } | |||
| if (StringUtils.isNotEmpty(params.getSheetName())) { | |||
| wb.setSheetName(0, params.getSheetName()); | |||
| } | |||
| // step 4. 解析模板 | |||
| // step 3. 解析模板 | |||
| parseTemplate(wb.getSheetAt(0), map); | |||
| if (dataSet != null) { | |||
| // step 5. 正常的数据填充 | |||
| // step 4. 正常的数据填充 | |||
| dataHanlder = params.getDataHanlder(); | |||
| if (dataHanlder != null) { | |||
| needHanlderList = Arrays.asList(dataHanlder | |||
| @@ -141,6 +141,9 @@ public class CellValueServer { | |||
| */ | |||
| private Object getCellValue(String xclass, Cell cell, | |||
| ExcelImportEntity entity) { | |||
| if(cell == null){ | |||
| return ""; | |||
| } | |||
| Object result = null; | |||
| // 日期格式比较特殊,和cell格式不一致 | |||
| if (xclass.equals("class java.util.Date")) { | |||
| @@ -94,6 +94,9 @@ public class ExcelImportServer { | |||
| } | |||
| Map<String, PictureData> pictures; | |||
| for (int i = 0; i < params.getSheetNum(); i++) { | |||
| if(logger.isDebugEnabled()){ | |||
| logger.debug(" start to read excel by is ,startTime is {}", new Date().getTime()); | |||
| } | |||
| if (isXSSFWorkbook) { | |||
| pictures = POIPublicUtil.getSheetPictrues07( | |||
| (XSSFSheet) book.getSheetAt(i), (XSSFWorkbook) book); | |||
| @@ -101,8 +104,14 @@ public class ExcelImportServer { | |||
| pictures = POIPublicUtil.getSheetPictrues03( | |||
| (HSSFSheet) book.getSheetAt(i), (HSSFWorkbook) book); | |||
| } | |||
| if(logger.isDebugEnabled()){ | |||
| logger.debug(" end to read excel by is ,endTime is {}", new Date().getTime()); | |||
| } | |||
| result.addAll(importExcel(result, book.getSheetAt(i), pojoClass, | |||
| params, pictures)); | |||
| if(logger.isDebugEnabled()){ | |||
| logger.debug(" end to read excel list by pos ,endTime is {}", new Date().getTime()); | |||
| } | |||
| } | |||
| if (params.isNeedSave()) { | |||
| saveThisExcel(params, pojoClass, isXSSFWorkbook, book); | |||
| @@ -141,8 +150,7 @@ public class ExcelImportServer { | |||
| if (params.getSaveUrl().equals("upload/excelUpload")) { | |||
| url = pojoClass.getName().split("\\.")[pojoClass.getName().split( | |||
| "\\.").length - 1]; | |||
| return params.getSaveUrl() + "/" | |||
| + url.substring(0, url.lastIndexOf("Entity")); | |||
| return params.getSaveUrl() + "/" + url; | |||
| } | |||
| return params.getSaveUrl(); | |||
| } | |||
| @@ -11,19 +11,19 @@ | |||
| <attribute name="maven.pomderived" value="true"/> | |||
| </attributes> | |||
| </classpathentry> | |||
| <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"> | |||
| <classpathentry kind="src" output="target/test-classes" path="src/test/java"> | |||
| <attributes> | |||
| <attribute name="optional" value="true"/> | |||
| <attribute name="maven.pomderived" value="true"/> | |||
| </attributes> | |||
| </classpathentry> | |||
| <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | |||
| <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"> | |||
| <attributes> | |||
| <attribute name="maven.pomderived" value="true"/> | |||
| </attributes> | |||
| </classpathentry> | |||
| <classpathentry kind="src" output="target/test-classes" path="src/test/java"> | |||
| <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | |||
| <attributes> | |||
| <attribute name="optional" value="true"/> | |||
| <attribute name="maven.pomderived" value="true"/> | |||
| </attributes> | |||
| </classpathentry> | |||
| @@ -4,7 +4,7 @@ | |||
| <parent> | |||
| <groupId>org.jeecgframework</groupId> | |||
| <artifactId>easypoi</artifactId> | |||
| <version>2.0.2</version> | |||
| <version>2.0.6-SNAPSHOT</version> | |||
| </parent> | |||
| <artifactId>easypoi-test</artifactId> | |||
| <dependencies> | |||
| @@ -0,0 +1,146 @@ | |||
| package org.jeecgframework.poi.entity; | |||
| import java.util.Date; | |||
| import org.jeecgframework.poi.excel.annotation.Excel; | |||
| import org.jeecgframework.poi.excel.annotation.ExcelEntity; | |||
| /** | |||
| * @Title: Entity | |||
| * @Description: 通讯录 | |||
| * @author JueYue | |||
| * @date 2014-09-22 16:03:32 | |||
| * @version V1.0 | |||
| * | |||
| */ | |||
| @SuppressWarnings("serial") | |||
| public class MsgClient implements java.io.Serializable { | |||
| /** id */ | |||
| private java.lang.String id; | |||
| // 电话号码(主键) | |||
| @Excel(name = "电话号码") | |||
| private String clientPhone = null; | |||
| // 客户姓名 | |||
| @Excel(name = "姓名") | |||
| private String clientName = null; | |||
| // 所属分组 | |||
| @ExcelEntity | |||
| private MsgClientGroup group = null; | |||
| // 备注 | |||
| @Excel(name = "备注") | |||
| private String remark = null; | |||
| // 生日 | |||
| @Excel(name = "出生日期") | |||
| private Date birthday = null; | |||
| // 创建人 | |||
| private String createBy = null; | |||
| /** | |||
| * 方法: 取得java.lang.String | |||
| * | |||
| * @return: java.lang.String id | |||
| */ | |||
| public java.lang.String getId() { | |||
| return this.id; | |||
| } | |||
| /** | |||
| * 方法: 设置java.lang.String | |||
| * | |||
| * @param: java.lang.String id | |||
| */ | |||
| public void setId(java.lang.String id) { | |||
| this.id = id; | |||
| } | |||
| /** | |||
| * 方法: 取得java.lang.String | |||
| * | |||
| * @return: java.lang.String 电话号码 | |||
| */ | |||
| public java.lang.String getClientPhone() { | |||
| return this.clientPhone; | |||
| } | |||
| /** | |||
| * 方法: 设置java.lang.String | |||
| * | |||
| * @param: java.lang.String 电话号码 | |||
| */ | |||
| public void setClientPhone(java.lang.String clientPhone) { | |||
| this.clientPhone = clientPhone; | |||
| } | |||
| public MsgClientGroup getGroup() { | |||
| return group; | |||
| } | |||
| public void setGroup(MsgClientGroup group) { | |||
| this.group = group; | |||
| } | |||
| /** | |||
| * 方法: 取得java.lang.String | |||
| * | |||
| * @return: java.lang.String 客户姓名 | |||
| */ | |||
| public java.lang.String getClientName() { | |||
| return this.clientName; | |||
| } | |||
| /** | |||
| * 方法: 设置java.lang.String | |||
| * | |||
| * @param: java.lang.String 客户姓名 | |||
| */ | |||
| public void setClientName(java.lang.String clientName) { | |||
| this.clientName = clientName; | |||
| } | |||
| /** | |||
| * 方法: 取得java.lang.String | |||
| * | |||
| * @return: java.lang.String 备注 | |||
| */ | |||
| public java.lang.String getRemark() { | |||
| return this.remark; | |||
| } | |||
| /** | |||
| * 方法: 设置java.lang.String | |||
| * | |||
| * @param remark | |||
| * | |||
| * @param: java.lang.String 备注 | |||
| */ | |||
| public void setRemark(java.lang.String remark) { | |||
| this.remark = remark; | |||
| } | |||
| /** | |||
| * 方法: 取得java.util.Date | |||
| * | |||
| * @return: java.util.Date 生日 | |||
| */ | |||
| public java.util.Date getBirthday() { | |||
| return this.birthday; | |||
| } | |||
| /** | |||
| * 方法: 设置java.util.Date | |||
| * | |||
| * @param: java.util.Date 生日 | |||
| */ | |||
| public void setBirthday(java.util.Date birthday) { | |||
| this.birthday = birthday; | |||
| } | |||
| public String getCreateBy() { | |||
| return createBy; | |||
| } | |||
| public void setCreateBy(String createBy) { | |||
| this.createBy = createBy; | |||
| } | |||
| } | |||
| @@ -0,0 +1,57 @@ | |||
| package org.jeecgframework.poi.entity; | |||
| import java.io.Serializable; | |||
| import java.util.List; | |||
| import org.jeecgframework.poi.excel.annotation.Excel; | |||
| /** | |||
| * 客户分组表 | |||
| * | |||
| * @author yjl | |||
| * | |||
| */ | |||
| public class MsgClientGroup implements Serializable{ | |||
| /** | |||
| * | |||
| */ | |||
| private static final long serialVersionUID = 6946265640897464878L; | |||
| // 组名 | |||
| @Excel(name ="分组") | |||
| private String groupName = null; | |||
| /** | |||
| * 创建人 | |||
| */ | |||
| private String createBy; | |||
| // 一个组下 可能存在N多客户 | |||
| //private List<MsgClientMine> clients = null; | |||
| public String getGroupName() { | |||
| return groupName; | |||
| } | |||
| public void setGroupName(String groupName) { | |||
| this.groupName = groupName; | |||
| } | |||
| /*@org.codehaus.jackson.annotate.JsonIgnore | |||
| @OneToMany(cascade = CascadeType.REMOVE,fetch = FetchType.LAZY,mappedBy = "group") | |||
| public List<MsgClientMine> getClients() { | |||
| return clients; | |||
| } | |||
| public void setClients(List<MsgClientMine> clients) { | |||
| this.clients = clients; | |||
| }*/ | |||
| public String getCreateBy() { | |||
| return createBy; | |||
| } | |||
| public void setCreateBy(String createBy) { | |||
| this.createBy = createBy; | |||
| } | |||
| } | |||
| @@ -4,9 +4,11 @@ import static org.junit.Assert.*; | |||
| import java.io.File; | |||
| import java.util.Collection; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import org.jeecgframework.poi.entity.CourseEntity; | |||
| import org.jeecgframework.poi.entity.MsgClient; | |||
| import org.jeecgframework.poi.entity.StudentEntity; | |||
| import org.jeecgframework.poi.excel.entity.ImportParams; | |||
| import org.junit.Test; | |||
| @@ -18,11 +20,13 @@ public class ExcelImportUtilTest { | |||
| ImportParams params = new ImportParams(); | |||
| params.setTitleRows(2); | |||
| params.setHeadRows(2); | |||
| //params.setSheetNum(9); | |||
| params.setNeedSave(true); | |||
| long start = new Date().getTime(); | |||
| List<CourseEntity> list = ExcelImportUtil.importExcel(new File( | |||
| "d:/tt.xls"), CourseEntity.class, params); | |||
| for (int i = 0; i < list.size(); i++) { | |||
| System.out.println(list.get(i).getName()); | |||
| } | |||
| System.out.println(list.size() + "-----" | |||
| + (new Date().getTime() - start)); | |||
| } | |||
| } | |||
| @@ -0,0 +1,51 @@ | |||
| package org.jeecgframework.poi.excel.test; | |||
| import static org.junit.Assert.*; | |||
| import org.apache.poi.hssf.usermodel.HSSFWorkbook; | |||
| import org.jeecgframework.poi.entity.TeacherEntity; | |||
| import org.jeecgframework.poi.excel.ExcelExportUtil; | |||
| import org.jeecgframework.poi.excel.entity.ExportParams; | |||
| import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; | |||
| import java.io.FileNotFoundException; | |||
| import java.io.FileOutputStream; | |||
| import java.io.IOException; | |||
| import java.util.ArrayList; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import org.junit.Test; | |||
| public class ExcelExportForMap { | |||
| @Test | |||
| public void test() { | |||
| try { | |||
| List<ExcelExportEntity> entity = new ArrayList<ExcelExportEntity>(); | |||
| entity.add(new ExcelExportEntity("姓名", "name")); | |||
| entity.add(new ExcelExportEntity("性别", "sex")); | |||
| List<Map<String, String>> list = new ArrayList<Map<String, String>>(); | |||
| Map<String, String> map; | |||
| for (int i = 0; i < 10; i++) { | |||
| map = new HashMap<String, String>(); | |||
| map.put("name", "1" + i); | |||
| map.put("sex", "2" + i); | |||
| list.add(map); | |||
| } | |||
| HSSFWorkbook workbook = ExcelExportUtil.exportExcel(new ExportParams( | |||
| "测试", "测试"), entity, list); | |||
| FileOutputStream fos = new FileOutputStream("d:/tt.xls"); | |||
| workbook.write(fos); | |||
| fos.close(); | |||
| } catch (FileNotFoundException e) { | |||
| e.printStackTrace(); | |||
| } catch (IOException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,108 @@ | |||
| package org.jeecgframework.poi.excel.test; | |||
| import java.io.File; | |||
| import java.io.FileNotFoundException; | |||
| import java.io.FileOutputStream; | |||
| import java.util.ArrayList; | |||
| import java.util.Date; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import org.apache.poi.ss.usermodel.Workbook; | |||
| import org.jeecgframework.poi.entity.CourseEntity; | |||
| import org.jeecgframework.poi.entity.StudentEntity; | |||
| import org.jeecgframework.poi.entity.TeacherEntity; | |||
| import org.jeecgframework.poi.excel.ExcelExportUtil; | |||
| import org.jeecgframework.poi.excel.entity.TemplateExportParams; | |||
| import org.junit.Before; | |||
| import org.junit.Test; | |||
| public class ExcelExportTemplateTest { | |||
| List<CourseEntity> list = new ArrayList<CourseEntity>(); | |||
| CourseEntity courseEntity; | |||
| @Before | |||
| public void testBefore() { | |||
| courseEntity = new CourseEntity(); | |||
| courseEntity.setId("1131"); | |||
| courseEntity.setName("小白"); | |||
| TeacherEntity teacherEntity = new TeacherEntity(); | |||
| teacherEntity.setId("12131231"); | |||
| teacherEntity.setName("你们"); | |||
| courseEntity.setTeacher(teacherEntity); | |||
| teacherEntity = new TeacherEntity(); | |||
| teacherEntity.setId("121312314312421131"); | |||
| teacherEntity.setName("老王"); | |||
| courseEntity.setShuxueteacher(teacherEntity); | |||
| StudentEntity studentEntity = new StudentEntity(); | |||
| studentEntity.setId("11231"); | |||
| studentEntity.setName("撒旦法司法局"); | |||
| studentEntity.setBirthday(new Date()); | |||
| studentEntity.setSex(1); | |||
| List<StudentEntity> studentList = new ArrayList<StudentEntity>(); | |||
| studentList.add(studentEntity); | |||
| studentList.add(studentEntity); | |||
| courseEntity.setStudents(studentList); | |||
| for (int i = 0; i < 3; i++) { | |||
| list.add(courseEntity); | |||
| } | |||
| } | |||
| //@Test | |||
| public void one () throws Exception{ | |||
| TemplateExportParams params = new TemplateExportParams(); | |||
| params.setHeadingRows(2); | |||
| params.setHeadingStartRow(2); | |||
| Map<String,Object> map = new HashMap<String, Object>(); | |||
| map.put("year", "2013"); | |||
| map.put("sunCourses", list.size()); | |||
| Map<String,Object> obj = new HashMap<String, Object>(); | |||
| map.put("obj", obj); | |||
| obj.put("name", list.size()); | |||
| params.setTemplateUrl("org/jeecgframework/poi/excel/doc/exportTemp.xls"); | |||
| Workbook book = ExcelExportUtil.exportExcel(params, CourseEntity.class, list, | |||
| map); | |||
| File savefile = new File("d:/"); | |||
| if (!savefile.exists()) { | |||
| savefile.mkdirs(); | |||
| } | |||
| FileOutputStream fos = new FileOutputStream("d:/exportTemp.xls"); | |||
| book.write(fos); | |||
| fos.close(); | |||
| } | |||
| @Test | |||
| public void two () throws Exception{ | |||
| TemplateExportParams params = new TemplateExportParams(); | |||
| Map<String,Object> map = new HashMap<String, Object>(); | |||
| map.put("month", 10); | |||
| Map<String,Object> temp; | |||
| for(int i = 1;i<8;i++){ | |||
| temp = new HashMap<String, Object>(); | |||
| temp.put("per", i*10); | |||
| temp.put("mon", i*1000); | |||
| temp.put("summon", i*10000); | |||
| map.put("i"+i, temp); | |||
| } | |||
| params.setTemplateUrl("org/jeecgframework/poi/excel/doc/exportTemp.xls"); | |||
| params.setSheetNum(1); | |||
| Workbook book = ExcelExportUtil.exportExcel(params, CourseEntity.class, list, | |||
| map); | |||
| File savefile = new File("d:/"); | |||
| if (!savefile.exists()) { | |||
| savefile.mkdirs(); | |||
| } | |||
| FileOutputStream fos = new FileOutputStream("d:/exportTemp2.xls"); | |||
| book.write(fos); | |||
| fos.close(); | |||
| } | |||
| } | |||
| @@ -59,7 +59,6 @@ public class ExcelExportUtilIdTest { | |||
| telist.add(teacherEntity); | |||
| } | |||
| } | |||
| /** | |||
| * 单行表头导出测试 | |||
| @@ -68,8 +67,10 @@ public class ExcelExportUtilIdTest { | |||
| */ | |||
| @Test | |||
| public void testExportExcel() throws Exception { | |||
| HSSFWorkbook workbook = ExcelExportUtil.exportExcel(new ExportParams( | |||
| "2412312", "测试", "测试"), TeacherEntity.class, telist); | |||
| ExportParams params = new ExportParams("2412312", "测试", "测试"); | |||
| params.setAddIndex(true); | |||
| HSSFWorkbook workbook = ExcelExportUtil.exportExcel(params, | |||
| TeacherEntity.class, telist); | |||
| FileOutputStream fos = new FileOutputStream("d:/tt.xls"); | |||
| workbook.write(fos); | |||
| fos.close(); | |||
| @@ -62,7 +62,7 @@ public class ExcelExportUtilTest { | |||
| * | |||
| * @throws Exception | |||
| */ | |||
| @Test | |||
| //@Test | |||
| public void testExportExcel() throws Exception { | |||
| Date start = new Date(); | |||
| HSSFWorkbook workbook = ExcelExportUtil.exportExcel(new ExportParams( | |||
| @@ -123,9 +123,10 @@ public class ExcelExportUtilTest { | |||
| * | |||
| * @throws Exception | |||
| */ | |||
| //@Test | |||
| @Test | |||
| public void oneHundredThousandRowTest() throws Exception { | |||
| for (int i = 0; i < 250000; i++) { | |||
| for (int i = 0; i < 250; i++) { | |||
| list.add(courseEntity); | |||
| } | |||
| Date start = new Date(); | |||
| @@ -139,6 +140,14 @@ public class ExcelExportUtilTest { | |||
| FileOutputStream fos = new FileOutputStream("d:/tt.xls"); | |||
| workbook.write(fos); | |||
| fos.close(); | |||
| savefile = new File("d:/1"); | |||
| if (!savefile.exists()) { | |||
| savefile.setWritable(true, false); | |||
| savefile.mkdirs(); | |||
| } | |||
| fos = new FileOutputStream("d:/1/tt3.xls"); | |||
| workbook.write(fos); | |||
| fos.close(); | |||
| } | |||
| } | |||
| @@ -0,0 +1,11 @@ | |||
| log4j.rootLogger=debug,A1,R | |||
| log4j.appender.A1=org.apache.log4j.ConsoleAppender | |||
| log4j.appender.A1.Target=System.out | |||
| log4j.appender.A1.layout=org.apache.log4j.PatternLayout | |||
| log4j.appender.A1.layout.ConversionPattern=[%c]%m%n | |||
| log4j.appender.R=org.apache.log4j.RollingFileAppender | |||
| log4j.appender.R.File=/home/logs/easypoi.info | |||
| log4j.appender.R.MaxFileSize=10MB | |||
| log4j.appender.R.layout=org.apache.log4j.PatternLayout | |||
| log4j.appender.R.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH\:mm\:ss,SSS}][%c]%m%n | |||
| @@ -11,19 +11,19 @@ | |||
| <attribute name="maven.pomderived" value="true"/> | |||
| </attributes> | |||
| </classpathentry> | |||
| <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"> | |||
| <classpathentry kind="src" output="target/test-classes" path="src/test/java"> | |||
| <attributes> | |||
| <attribute name="optional" value="true"/> | |||
| <attribute name="maven.pomderived" value="true"/> | |||
| </attributes> | |||
| </classpathentry> | |||
| <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | |||
| <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"> | |||
| <attributes> | |||
| <attribute name="maven.pomderived" value="true"/> | |||
| </attributes> | |||
| </classpathentry> | |||
| <classpathentry kind="src" output="target/test-classes" path="src/test/java"> | |||
| <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | |||
| <attributes> | |||
| <attribute name="optional" value="true"/> | |||
| <attribute name="maven.pomderived" value="true"/> | |||
| </attributes> | |||
| </classpathentry> | |||
| @@ -15,8 +15,14 @@ | |||
| <arguments> | |||
| </arguments> | |||
| </buildCommand> | |||
| <buildCommand> | |||
| <name>org.springframework.ide.eclipse.core.springbuilder</name> | |||
| <arguments> | |||
| </arguments> | |||
| </buildCommand> | |||
| </buildSpec> | |||
| <natures> | |||
| <nature>org.springframework.ide.eclipse.core.springnature</nature> | |||
| <nature>org.eclipse.jdt.core.javanature</nature> | |||
| <nature>org.eclipse.m2e.core.maven2Nature</nature> | |||
| </natures> | |||
| @@ -4,10 +4,9 @@ | |||
| <parent> | |||
| <groupId>org.jeecgframework</groupId> | |||
| <artifactId>easypoi</artifactId> | |||
| <version>2.0.2</version> | |||
| <version>2.0.6-SNAPSHOT</version> | |||
| </parent> | |||
| <artifactId>easypoi-web</artifactId> | |||
| <dependencies> | |||
| <!--spring --> | |||
| <dependency> | |||
| @@ -0,0 +1,22 @@ | |||
| package org.jeecgframework.poi.excel.entity.vo; | |||
| /** | |||
| * 正常导出Excel | |||
| * @Author JueYue on 14-3-8. | |||
| * 静态常量 | |||
| */ | |||
| public interface MapExcelConstants extends BasePOIConstants { | |||
| /** | |||
| * 单Sheet导出 | |||
| */ | |||
| public final static String JEECG_MAP_EXCEL_VIEW = "jeecgMapExcelView"; | |||
| /** | |||
| * Entity List | |||
| */ | |||
| public final static String ENTITY_LIST = "data"; | |||
| /** | |||
| * 数据列表 | |||
| */ | |||
| public final static String MAP_LIST = "mapList"; | |||
| } | |||
| @@ -0,0 +1,56 @@ | |||
| package org.jeecgframework.poi.excel.view; | |||
| import org.apache.poi.hssf.usermodel.HSSFWorkbook; | |||
| import org.jeecgframework.poi.excel.entity.ExportParams; | |||
| import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity; | |||
| import org.jeecgframework.poi.excel.entity.vo.MapExcelConstants; | |||
| import org.jeecgframework.poi.excel.export.ExcelExportServer; | |||
| import org.springframework.web.servlet.view.document.AbstractExcelView; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import javax.servlet.http.HttpServletResponse; | |||
| import java.util.Collection; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| /** | |||
| * Map 对象接口 | |||
| * | |||
| * @author JueYue | |||
| * @date 2014年11月25日 下午3:26:32 | |||
| */ | |||
| @SuppressWarnings("unchecked") | |||
| public class JeecgMapExcelView extends AbstractExcelView { | |||
| @Override | |||
| protected void buildExcelDocument(Map<String, Object> model, | |||
| HSSFWorkbook hssfWorkbook, HttpServletRequest httpServletRequest, | |||
| HttpServletResponse httpServletResponse) throws Exception { | |||
| String codedFileName = "临时文件.xls"; | |||
| if (model.containsKey(MapExcelConstants.FILE_NAME)) { | |||
| codedFileName = (String) model.get(MapExcelConstants.FILE_NAME) | |||
| + ".xls"; | |||
| } | |||
| if (isIE(httpServletRequest)) { | |||
| codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8"); | |||
| } else { | |||
| codedFileName = new String(codedFileName.getBytes("UTF-8"), | |||
| "ISO-8859-1"); | |||
| } | |||
| httpServletResponse.setHeader("content-disposition", | |||
| "attachment;filename=" + codedFileName); | |||
| new ExcelExportServer().createSheetForMap(hssfWorkbook, | |||
| (ExportParams) model.get(MapExcelConstants.PARAMS), | |||
| (List<ExcelExportEntity>) model | |||
| .get(MapExcelConstants.ENTITY_LIST), | |||
| (Collection<? extends Map<?, ?>>) model | |||
| .get(MapExcelConstants.MAP_LIST)); | |||
| } | |||
| 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; | |||
| } | |||
| } | |||
| @@ -28,17 +28,24 @@ public class JeecgSingleExcelView extends AbstractExcelView { | |||
| codedFileName = (String) model.get(NormalExcelConstants.FILE_NAME) | |||
| + ".xls"; | |||
| } | |||
| if (isIE(httpServletRequest)) { | |||
| codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8"); | |||
| } else { | |||
| codedFileName = new String(codedFileName.getBytes("UTF-8"), | |||
| "ISO-8859-1"); | |||
| } | |||
| httpServletResponse.setHeader("content-disposition", | |||
| "attachment;filename=" | |||
| + new String(codedFileName.getBytes(), "iso8859-1")); | |||
| "attachment;filename="+codedFileName); | |||
| if (model.containsKey(NormalExcelConstants.MAP_LIST)) { | |||
| List<Map<String, Object>> list = (List<Map<String, Object>>) model | |||
| .get(NormalExcelConstants.MAP_LIST); | |||
| for (Map<String, Object> map : list) { | |||
| new ExcelExportServer().createSheet(hssfWorkbook, | |||
| (ExportParams) map.get(NormalExcelConstants.PARAMS), | |||
| (Class<?>) map.get(NormalExcelConstants.CLASS), | |||
| (Collection<?>) map.get(NormalExcelConstants.DATA_LIST)); | |||
| new ExcelExportServer() | |||
| .createSheet(hssfWorkbook, (ExportParams) map | |||
| .get(NormalExcelConstants.PARAMS), | |||
| (Class<?>) map.get(NormalExcelConstants.CLASS), | |||
| (Collection<?>) map | |||
| .get(NormalExcelConstants.DATA_LIST)); | |||
| } | |||
| } else { | |||
| new ExcelExportServer().createSheet(hssfWorkbook, | |||
| @@ -47,4 +54,10 @@ public class JeecgSingleExcelView extends AbstractExcelView { | |||
| (Collection<?>) model.get(NormalExcelConstants.DATA_LIST)); | |||
| } | |||
| } | |||
| 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; | |||
| } | |||
| } | |||
| @@ -38,8 +38,14 @@ public class JeecgTemplateExcelView extends AbstractView { | |||
| codedFileName = (String) model.get(NormalExcelConstants.FILE_NAME) | |||
| + ".xls"; | |||
| } | |||
| response.setHeader("content-disposition", "attachment;filename=" | |||
| + new String(codedFileName.getBytes(), "iso8859-1")); | |||
| if (isIE(request)) { | |||
| codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8"); | |||
| } else { | |||
| codedFileName = new String(codedFileName.getBytes("UTF-8"), | |||
| "ISO-8859-1"); | |||
| } | |||
| response.setHeader("content-disposition", | |||
| "attachment;filename="+codedFileName); | |||
| Workbook workbook = ExcelExportUtil.exportExcel( | |||
| (TemplateExportParams)model.get(TemplateExcelConstants.PARAMS), | |||
| (Class<?>) model.get(TemplateExcelConstants.CLASS), | |||
| @@ -49,4 +55,10 @@ public class JeecgTemplateExcelView extends AbstractView { | |||
| workbook.write(out); | |||
| out.flush(); | |||
| } | |||
| 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; | |||
| } | |||
| } | |||
| @@ -35,12 +35,26 @@ public class JeecgTemplateWordView extends AbstractView { | |||
| codedFileName = (String) model.get(TemplateWordConstants.FILE_NAME) | |||
| + ".docx"; | |||
| } | |||
| if (isIE(request)) { | |||
| codedFileName = java.net.URLEncoder.encode(codedFileName, "UTF8"); | |||
| } else { | |||
| codedFileName = new String(codedFileName.getBytes("UTF-8"), | |||
| "ISO-8859-1"); | |||
| } | |||
| response.setHeader("content-disposition", "attachment;filename=" | |||
| + new String(codedFileName.getBytes(), "iso8859-1")); | |||
| XWPFDocument document = WordExportUtil.exportWord07((String)model.get(TemplateWordConstants.URL), | |||
| (Map<String, Object>)model.get(TemplateWordConstants.MAP_DATA)); | |||
| + codedFileName); | |||
| XWPFDocument document = WordExportUtil | |||
| .exportWord07((String) model.get(TemplateWordConstants.URL), | |||
| (Map<String, Object>) model | |||
| .get(TemplateWordConstants.MAP_DATA)); | |||
| ServletOutputStream out = response.getOutputStream(); | |||
| document.write(out); | |||
| out.flush(); | |||
| } | |||
| 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; | |||
| } | |||
| } | |||
| @@ -1 +1 @@ | |||
| cmd /k mvn package | |||
| cmd /k mvn package -DskipTest | |||
| @@ -3,7 +3,7 @@ | |||
| <modelVersion>4.0.0</modelVersion> | |||
| <groupId>org.jeecgframework</groupId> | |||
| <artifactId>easypoi</artifactId> | |||
| <version>2.0.2</version> | |||
| <version>2.0.6-SNAPSHOT</version> | |||
| <packaging>pom</packaging> | |||
| <name>easypoi</name> | |||
| <modules> | |||
| @@ -11,18 +11,19 @@ | |||
| <module>easypoi-web</module> | |||
| <module>easypoi-test</module> | |||
| </modules> | |||
| <url>www.jeecg.org</url> | |||
| <description> office 工具类 基于 poi</description> | |||
| <developers> | |||
| <developer> | |||
| <name>JueYue</name> | |||
| <email>qrb.jueyue@gmail.com</email> | |||
| </developer> | |||
| </developers> | |||
| <properties> | |||
| <sub.version>2.0.6-SNAPSHOT</sub.version> | |||
| <poi-ooxml-schemas.version>3.9</poi-ooxml-schemas.version> | |||
| <poi-ooxml.version>3.9</poi-ooxml.version> | |||
| <poi-scratchpad.version>3.9</poi-scratchpad.version> | |||
| @@ -109,7 +110,7 @@ | |||
| <version>2.5</version> | |||
| <scope>provided</scope> | |||
| </dependency> | |||
| <!-- test --> | |||
| <dependency> | |||
| <groupId>junit</groupId> | |||
| @@ -117,16 +118,17 @@ | |||
| <version>${junit.version}</version> | |||
| <scope>test</scope> | |||
| </dependency> | |||
| <!-- 模块版本 --> | |||
| <dependency> | |||
| <groupId>org.jeecgframework</groupId> | |||
| <artifactId>easypoi-base</artifactId> | |||
| <version>2.0.2</version> | |||
| <version>${sub.version}</version> | |||
| </dependency> | |||
| </dependencies> | |||
| </dependencyManagement> | |||
| <!-- 内部 maven 地址 --> | |||
| <distributionManagement> | |||
| <repository> | |||
| <id>postaop-pay-platform-release</id> | |||
| @@ -134,10 +136,15 @@ | |||
| </repository> | |||
| <snapshotRepository> | |||
| <id>postaop-pay-platform-snapshot</id> | |||
| <url>http://192.168.0.99:8081/nexus/content/repositoriespostaop-common-snapshot/</url> | |||
| <url>http://192.168.0.99:8081/nexus/content/repositories/postaop-common-snapshot/</url> | |||
| </snapshotRepository> | |||
| </distributionManagement> | |||
| <scm> | |||
| <connection>scm:svn:https://192.168.0.99:8443/svn/postaop-platform/qdcrm/trunk/</connection> | |||
| <developerConnection>scm:svn:https://192.168.0.99:8443/svn/postaop-platform/qdcrm/trunk/</developerConnection> | |||
| </scm> | |||
| <build> | |||
| <plugins> | |||
| <plugin> | |||