From 2706bfe1bf8478bd7ae8df1ed2446acdb0fa0640 Mon Sep 17 00:00:00 2001 From: maijh <1198613361@qq.com> Date: Mon, 22 Jan 2018 20:47:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=BB=A1=E8=B6=B3=E4=B8=9A=E5=8A=A1=E9=9C=80?= =?UTF-8?q?=E8=A6=81=EF=BC=8C=E5=9C=A8=E5=AF=BC=E5=87=BAExcel=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E6=8C=87=E5=AE=9A=E6=9F=90=E4=BA=9B=E5=88=97=E9=9A=90?= =?UTF-8?q?=E8=97=8F=E3=80=82=E5=A2=9E=E5=8A=A0@Excel=20=E6=B3=A8=E8=A7=A3?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=20isColumnHidden=20=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E9=9A=90=E8=97=8F=E5=88=97=20,=E4=BD=9C=E7=94=A8=E9=9A=90?= =?UTF-8?q?=E8=97=8Fexcel=E8=A1=A8=E6=A0=BC=E5=88=97=20=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20=E9=82=AE=E7=AE=B1=EF=BC=9Axiaomai=5Fh@163.com?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../easypoi/excel/annotation/Excel.java | 14 +++++++++---- .../entity/params/ExcelExportEntity.java | 18 +++++++++++++--- .../excel/export/ExcelExportService.java | 1 + .../excel/export/base/BaseExportService.java | 21 +++++++++++++++++-- .../export/base/ExportCommonService.java | 1 + 5 files changed, 46 insertions(+), 9 deletions(-) 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 {