| @@ -1,6 +1,6 @@ | |||||
| /** | /** | ||||
| * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) | ||||
| * | |||||
| * | |||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| * you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
| * You may obtain a copy of the License at | * You may obtain a copy of the License at | ||||
| @@ -115,7 +115,7 @@ public @interface Excel { | |||||
| /** | /** | ||||
| * 导入路径,如果是图片可以填写,默认是upload/className/ IconEntity这个类对应的就是upload/Icon/ | * 导入路径,如果是图片可以填写,默认是upload/className/ IconEntity这个类对应的就是upload/Icon/ | ||||
| * | |||||
| * | |||||
| */ | */ | ||||
| public String savePath() default "upload"; | public String savePath() default "upload"; | ||||
| @@ -136,13 +136,13 @@ public @interface Excel { | |||||
| * @return | * @return | ||||
| */ | */ | ||||
| public boolean isStatistics() default false; | public boolean isStatistics() default false; | ||||
| /** | /** | ||||
| * 这个是不是超链接,如果是需要实现接口返回对象 | * 这个是不是超链接,如果是需要实现接口返回对象 | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| public boolean isHyperlink() default false; | public boolean isHyperlink() default false; | ||||
| /** | /** | ||||
| * 导入时会校验这个字段,看看这个字段是不是导入的Excel中有,如果没有说明是错误的Excel | * 导入时会校验这个字段,看看这个字段是不是导入的Excel中有,如果没有说明是错误的Excel | ||||
| * 本意是想用true的,想想还是false比较好 | * 本意是想用true的,想想还是false比较好 | ||||
| @@ -156,4 +156,10 @@ public @interface Excel { | |||||
| * @return | * @return | ||||
| */ | */ | ||||
| public int fixedIndex() default -1; | public int fixedIndex() default -1; | ||||
| /** | |||||
| * 是否需要隐藏该列 | |||||
| * @return | |||||
| */ | |||||
| public boolean isColumnHidden() default false; | |||||
| } | } | ||||
| @@ -1,6 +1,6 @@ | |||||
| /** | /** | ||||
| * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) | * Copyright 2013-2015 JueYue (qrb.jueyue@gmail.com) | ||||
| * | |||||
| * | |||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| * you may not use this file except in compliance with the License. | * you may not use this file except in compliance with the License. | ||||
| * You may obtain a copy of the License at | * You may obtain a copy of the License at | ||||
| @@ -19,7 +19,7 @@ import java.util.List; | |||||
| /** | /** | ||||
| * excel 导出工具类,对cell类型做映射 | * excel 导出工具类,对cell类型做映射 | ||||
| * | |||||
| * | |||||
| * @author JueYue | * @author JueYue | ||||
| * @version 1.0 2013年8月24日 | * @version 1.0 2013年8月24日 | ||||
| */ | */ | ||||
| @@ -58,7 +58,7 @@ public class ExcelExportEntity extends ExcelBaseEntity implements Comparable<Exc | |||||
| */ | */ | ||||
| private boolean mergeVertical; | private boolean mergeVertical; | ||||
| /** | /** | ||||
| * 合并依赖 | |||||
| * 合并依赖` | |||||
| */ | */ | ||||
| private int[] mergeRely; | private int[] mergeRely; | ||||
| /** | /** | ||||
| @@ -71,6 +71,18 @@ public class ExcelExportEntity extends ExcelBaseEntity implements Comparable<Exc | |||||
| private boolean isStatistics; | private boolean isStatistics; | ||||
| private String numFormat; | private String numFormat; | ||||
| /** | |||||
| * 是否隐藏列 | |||||
| */ | |||||
| private boolean isColumnHidden; | |||||
| public boolean isColumnHidden() { | |||||
| return isColumnHidden; | |||||
| } | |||||
| public void setColumnHidden(boolean columnHidden) { | |||||
| isColumnHidden = columnHidden; | |||||
| } | |||||
| private List<ExcelExportEntity> list; | private List<ExcelExportEntity> list; | ||||
| @@ -167,6 +167,7 @@ public class ExcelExportService extends BaseExportService { | |||||
| ? createHeaderAndTitle(entity, sheet, workbook, excelParams) : 0; | ? createHeaderAndTitle(entity, sheet, workbook, excelParams) : 0; | ||||
| int titleHeight = index; | int titleHeight = index; | ||||
| setCellWith(excelParams, sheet); | setCellWith(excelParams, sheet); | ||||
| setColumnHidden(excelParams,sheet); | |||||
| short rowHeight = entity.getHeight() > 0 ? entity.getHeight() : getRowHeight(excelParams); | short rowHeight = entity.getHeight() > 0 ? entity.getHeight() : getRowHeight(excelParams); | ||||
| setCurrentIndex(1); | setCurrentIndex(1); | ||||
| Iterator<?> its = dataSet.iterator(); | Iterator<?> its = dataSet.iterator(); | ||||
| @@ -114,8 +114,8 @@ public abstract class BaseExportService extends ExportCommonService { | |||||
| entity); | entity); | ||||
| if (entity.isHyperlink()) { | if (entity.isHyperlink()) { | ||||
| row.getCell(cellNum - 1).setHyperlink(dataHanlder.getHyperlink( | row.getCell(cellNum - 1).setHyperlink(dataHanlder.getHyperlink( | ||||
| row.getSheet().getWorkbook().getCreationHelper(), t, | |||||
| entity.getName(), value)); | |||||
| row.getSheet().getWorkbook().getCreationHelper(), t, | |||||
| entity.getName(), value)); | |||||
| } | } | ||||
| } else { | } else { | ||||
| createImageCell(patriarch, entity, row, cellNum++, | createImageCell(patriarch, entity, row, cellNum++, | ||||
| @@ -390,6 +390,23 @@ public abstract class BaseExportService extends ExportCommonService { | |||||
| } | } | ||||
| } | } | ||||
| public void setColumnHidden(List<ExcelExportEntity> excelParams, Sheet sheet){ | |||||
| int index = 0; | |||||
| for (int i = 0; i < excelParams.size(); i++) { | |||||
| if (excelParams.get(i).getList() != null) { | |||||
| List<ExcelExportEntity> list = excelParams.get(i).getList(); | |||||
| for (int j = 0; j < list.size(); j++) { | |||||
| sheet.setColumnHidden(index,list.get(i).isColumnHidden()); | |||||
| index++; | |||||
| } | |||||
| } else { | |||||
| sheet.setColumnHidden(index,excelParams.get(i).isColumnHidden());; | |||||
| index++; | |||||
| } | |||||
| } | |||||
| } | |||||
| public void setCurrentIndex(int currentIndex) { | public void setCurrentIndex(int currentIndex) { | ||||
| this.currentIndex = currentIndex; | this.currentIndex = currentIndex; | ||||
| } | } | ||||
| @@ -242,6 +242,7 @@ public class ExportCommonService { | |||||
| excelEntity.setHyperlink(excel.isHyperlink()); | excelEntity.setHyperlink(excel.isHyperlink()); | ||||
| excelEntity.setMethod(PoiReflectorUtil.fromCache(pojoClass).getGetMethod(field.getName())); | excelEntity.setMethod(PoiReflectorUtil.fromCache(pojoClass).getGetMethod(field.getName())); | ||||
| excelEntity.setNumFormat(excel.numFormat()); | excelEntity.setNumFormat(excel.numFormat()); | ||||
| excelEntity.setColumnHidden(excel.isColumnHidden()); | |||||
| if (excelGroup != null) { | if (excelGroup != null) { | ||||
| excelEntity.setGroupName(PoiPublicUtil.getValueByTargetId(excelGroup.name(), targetId, null)); | excelEntity.setGroupName(PoiPublicUtil.getValueByTargetId(excelGroup.name(), targetId, null)); | ||||
| } else { | } else { | ||||