POI操作EXCEL增加下拉框


文章目录


POI操作EXCEL增加下拉框

有时候通过excel将数据批量导入到系统,而业务操作人员对于一些列不想手动输入,而是采用下拉框的方式来进行选择

采用隐藏sheet页的方式来进行操作

java 复制代码
String sheetName = "supplier_hidden_sheet";

HSSFSheet supplierSheet = workbook.createSheet(sheetName);//隐藏的sheet,用于存放下拉框的限定值
int count = 0;
for(String supplierName : suppliers){
    supplierSheet.createRow(count++).createCell(0).setCellValue(supplierName);
}
      
String col = "A";

//设置数据有效性加载在哪个单元格上,四个参数分别是:起始行、终止行、起始列、终止列
CellRangeAddressList regions = new CellRangeAddressList(1, dataList.size(), supplierColumn, supplierColumn);
// 这是表示从隐藏sheet页的哪列哪行到哪列哪行  如该格式 supplier_hidden_sheet!$A$1:$A$73 
String cell = "\""+sheetName +"!$"+col+"$1:$"+col+"$"+suppliers.size()+"\"";
// 引用ShtDictionary 的单元格
DVConstraint constraint = DVConstraint.createFormulaListConstraint("INDIRECT("+cell+ ")");
// 数据检验为该格式  =INDIRECT("supplier_hidden_sheet!$A$1:$A$73")
HSSFDataValidation dataValidate = new HSSFDataValidation(regions, constraint);
sheet.addValidationData(dataValidate);
workbook.setSheetHidden(1,true);

可以在EXCEL中的数据有效性看到数据来源

参考文献

相关推荐
UR的出不克13 小时前
使用 Python 爬取 Bilibili 弹幕数据并导出 Excel
java·python·excel
wtsolutions13 小时前
Understanding Excel Data Formats - What Excel to JSON Supports
ui·json·excel
ぁず14 小时前
excel想生成一列随机数并删除公式保留值
excel
wtsolutions17 小时前
Real-World Use Cases - How Organizations Use Excel to JSON
json·github·excel
一只小H呀の17 小时前
pandas处理excel数据
excel·pandas
wregjru17 小时前
【操作系统】3.开发工具
excel
wtsolutions19 小时前
MCP Service Integration - Excel to JSON for AI and Automation
人工智能·json·excel
wtsolutions1 天前
JSON to Excel Add-in - Seamless Integration Within Excel
json·excel
wtsolutions1 天前
Getting Started with JSON to Excel Web App - Convert in Seconds
json·excel·web app
wtsolutions1 天前
Using the JSON to Excel API - Programmatic Access for Developers
json·excel