diff --git a/easypoi-annotation/src/main/java/cn/afterturn/easypoi/excel/annotation/Excel.java b/easypoi-annotation/src/main/java/cn/afterturn/easypoi/excel/annotation/Excel.java index bc6cac5..9e465c4 100644 --- a/easypoi-annotation/src/main/java/cn/afterturn/easypoi/excel/annotation/Excel.java +++ b/easypoi-annotation/src/main/java/cn/afterturn/easypoi/excel/annotation/Excel.java @@ -1,6 +1,6 @@ /** * 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 @@ -115,7 +115,7 @@ public @interface Excel { /** * 导入路径,如果是图片可以填写,默认是upload/className/ IconEntity这个类对应的就是upload/Icon/ - * + * */ public String savePath() default "upload"; @@ -136,13 +136,13 @@ public @interface Excel { * @return */ public boolean isStatistics() default false; - + /** * 这个是不是超链接,如果是需要实现接口返回对象 * @return */ public boolean isHyperlink() default false; - + /** * 导入时会校验这个字段,看看这个字段是不是导入的Excel中有,如果没有说明是错误的Excel * 本意是想用true的,想想还是false比较好 @@ -156,4 +156,10 @@ public @interface Excel { * @return */ public int fixedIndex() default -1; + + /** + * 是否需要隐藏该列 + * @return + */ + public boolean isColumnHidden() default false; } diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelExportEntity.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelExportEntity.java index cd7e890..98d3bde 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelExportEntity.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelExportEntity.java @@ -1,6 +1,6 @@ /** * 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 @@ -19,7 +19,7 @@ import java.util.List; /** * excel 导出工具类,对cell类型做映射 - * + * * @author JueYue * @version 1.0 2013年8月24日 */ @@ -58,7 +58,7 @@ public class ExcelExportEntity extends ExcelBaseEntity implements Comparable list; diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/ExcelExportService.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/ExcelExportService.java index 705cb54..bb17591 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/ExcelExportService.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/ExcelExportService.java @@ -167,6 +167,7 @@ public class ExcelExportService extends BaseExportService { ? createHeaderAndTitle(entity, sheet, workbook, excelParams) : 0; int titleHeight = index; setCellWith(excelParams, sheet); + setColumnHidden(excelParams,sheet); short rowHeight = entity.getHeight() > 0 ? entity.getHeight() : getRowHeight(excelParams); setCurrentIndex(1); Iterator its = dataSet.iterator(); diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/BaseExportService.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/BaseExportService.java index 61e6cb5..ac9089f 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/BaseExportService.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/BaseExportService.java @@ -114,8 +114,8 @@ public abstract class BaseExportService extends ExportCommonService { entity); if (entity.isHyperlink()) { row.getCell(cellNum - 1).setHyperlink(dataHanlder.getHyperlink( - row.getSheet().getWorkbook().getCreationHelper(), t, - entity.getName(), value)); + row.getSheet().getWorkbook().getCreationHelper(), t, + entity.getName(), value)); } } else { createImageCell(patriarch, entity, row, cellNum++, @@ -390,6 +390,23 @@ public abstract class BaseExportService extends ExportCommonService { } } + + public void setColumnHidden(List excelParams, Sheet sheet){ + int index = 0; + for (int i = 0; i < excelParams.size(); i++) { + if (excelParams.get(i).getList() != null) { + List 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) { this.currentIndex = currentIndex; } diff --git a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/ExportCommonService.java b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/ExportCommonService.java index ca14d11..84a9b1a 100644 --- a/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/ExportCommonService.java +++ b/easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/base/ExportCommonService.java @@ -242,6 +242,7 @@ public class ExportCommonService { excelEntity.setHyperlink(excel.isHyperlink()); excelEntity.setMethod(PoiReflectorUtil.fromCache(pojoClass).getGetMethod(field.getName())); excelEntity.setNumFormat(excel.numFormat()); + excelEntity.setColumnHidden(excel.isColumnHidden()); if (excelGroup != null) { excelEntity.setGroupName(PoiPublicUtil.getValueByTargetId(excelGroup.name(), targetId, null)); } else {