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); + + } + + + }