| | |
| | | * 这里需要根据实际情况从区域数据源获取 |
| | | * </p> |
| | | */ |
| | | private static final String[] REGION_NAMES = { |
| | | "吉州区", "青原区", "吉安县", "吉水县", "峡江县", "新干县", "永丰县", "泰和县", "遂川县", "万安县" |
| | | }; |
| | | |
| | | private static final String[] REGION_NAMES = { "市级", "区县级", "街道级" }; |
| | | // 启用 禁用 |
| | | private static final String[] ENABLE_DISABLE = { "启用", "禁用" }; |
| | | |
| | | @Override |
| | | public void beforeSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) { |
| | |
| | | |
| | | // 为区域列添加下拉选择 |
| | | // 假设区域列是第3列(索引为1),从第2行开始(索引为1) |
| | | addRegionValidation(workbook, sheet, 1, 1, 1000); |
| | | addRegionValidation(workbook, sheet, 3, 1, 1000, REGION_NAMES); |
| | | addRegionValidation(workbook, sheet, 5, 1, 1000, ENABLE_DISABLE); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param startRow 开始行索引 |
| | | * @param endRow 结束行索引 |
| | | */ |
| | | private void addRegionValidation(Workbook workbook, Sheet sheet, int column, int startRow, int endRow) { |
| | | private void addRegionValidation(Workbook workbook, Sheet sheet, int column, int startRow, int endRow, String[] regionNames) { |
| | | // 创建数据验证助手 |
| | | DataValidationHelper helper = sheet.getDataValidationHelper(); |
| | | |
| | | // 创建下拉列表约束 |
| | | DataValidationConstraint constraint = helper.createExplicitListConstraint(REGION_NAMES); |
| | | DataValidationConstraint constraint = helper.createExplicitListConstraint(regionNames); |
| | | |
| | | // 创建数据验证区域 |
| | | CellRangeAddressList addressList = new CellRangeAddressList(startRow, endRow, column, column); |
| | |
| | | // 添加数据验证到工作表 |
| | | sheet.addValidationData(validation); |
| | | } |
| | | |
| | | |
| | | } |