From 19966fd1c7128c91db2cbee08439bab4f206d0e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=A8=E6=9C=A8c?= <857448963@qq.com> Date: Fri, 1 Jul 2022 10:31:34 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E8=83=BD=E7=A9=BA=E8=B0=83=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=8F=90=E4=BA=A4=20=E7=BB=88=E7=AB=AF=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BB=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/njcn/poi/excel/ExcelUtil.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pqs-common/common-poi/src/main/java/com/njcn/poi/excel/ExcelUtil.java b/pqs-common/common-poi/src/main/java/com/njcn/poi/excel/ExcelUtil.java index 344aacf6b..27a0e188a 100644 --- a/pqs-common/common-poi/src/main/java/com/njcn/poi/excel/ExcelUtil.java +++ b/pqs-common/common-poi/src/main/java/com/njcn/poi/excel/ExcelUtil.java @@ -5,7 +5,11 @@ import cn.afterturn.easypoi.excel.entity.ExportParams; import cn.hutool.core.util.CharsetUtil; import com.njcn.web.utils.HttpServletUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.poi.hssf.usermodel.DVConstraint; +import org.apache.poi.hssf.usermodel.HSSFDataValidation; +import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.util.CellRangeAddressList; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; @@ -80,4 +84,27 @@ public class ExcelUtil { } + /** + * firstRow 開始行號 根据此项目,默认为2(下标0开始) + * lastRow 根据此项目,默认为最大65535 + * @param firstCol 区域中第一个单元格的列号 (下标0开始) + * @param lastCol 区域中最后一个单元格的列号 + * @param strings 下拉内容 + * */ + public static void selectList(Workbook workbook,int firstCol,int lastCol,String[] strings ){ + + Sheet sheet = workbook.getSheetAt(0); + // 生成下拉列表 + // 只对(x,x)单元格有效 + CellRangeAddressList cellRangeAddressList = new CellRangeAddressList(3, 65535, firstCol, lastCol); + // 生成下拉框内容 + DVConstraint dvConstraint = DVConstraint.createExplicitListConstraint(strings); + HSSFDataValidation dataValidation = new HSSFDataValidation(cellRangeAddressList, dvConstraint); + // 对sheet页生效 + sheet.addValidationData(dataValidation); + + } + + + }