Commit a0fcfb9021d6ce747b91753e2dd2d3199a2c2533
1 parent
a150a5e1
模板下载动态赋值单位下拉选
Showing
1 changed file
with
9 additions
and
11 deletions
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/costfee/CostFeeController.java
| ... | ... | @@ -15,9 +15,8 @@ import lombok.AllArgsConstructor; |
| 15 | 15 | import lombok.Data; |
| 16 | 16 | import lombok.extern.slf4j.Slf4j; |
| 17 | 17 | import org.apache.poi.ss.usermodel.*; |
| 18 | -import org.apache.poi.ss.util.CellRangeAddress; | |
| 19 | 18 | import org.apache.poi.ss.util.CellRangeAddressList; |
| 20 | -import org.apache.poi.xssf.usermodel.*; | |
| 19 | +import org.apache.poi.xssf.usermodel.XSSFWorkbook; | |
| 21 | 20 | import org.springframework.beans.factory.annotation.Autowired; |
| 22 | 21 | import org.springframework.beans.factory.annotation.Value; |
| 23 | 22 | import org.springframework.core.io.Resource; |
| ... | ... | @@ -32,9 +31,7 @@ import java.io.InputStream; |
| 32 | 31 | import java.io.OutputStream; |
| 33 | 32 | import java.lang.reflect.Method; |
| 34 | 33 | import java.net.URLEncoder; |
| 35 | -import java.nio.charset.StandardCharsets; | |
| 36 | 34 | import java.util.*; |
| 37 | -import java.util.stream.Collectors; | |
| 38 | 35 | |
| 39 | 36 | import static com.zteits.urbanops.framework.common.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST; |
| 40 | 37 | import static com.zteits.urbanops.framework.common.pojo.CommonResult.success; |
| ... | ... | @@ -124,7 +121,7 @@ public class CostFeeController{ |
| 124 | 121 | XSSFWorkbook workbook = new XSSFWorkbook(in); |
| 125 | 122 | OutputStream out = response.getOutputStream()) { |
| 126 | 123 | |
| 127 | - XSSFSheet sheet = workbook.getSheetAt(0); | |
| 124 | + Sheet sheet = workbook.getSheetAt(0); | |
| 128 | 125 | |
| 129 | 126 | // ============================================== |
| 130 | 127 | // 获取最新单位列表 |
| ... | ... | @@ -155,7 +152,7 @@ public class CostFeeController{ |
| 155 | 152 | /** |
| 156 | 153 | * 创建下拉框 + 给单元格赋值 |
| 157 | 154 | */ |
| 158 | - private void createDropdownAndSetValue(XSSFSheet sheet, List<String> options, int startRow) { | |
| 155 | + private void createDropdownAndSetValue(Sheet sheet, List<String> options, int startRow) { | |
| 159 | 156 | if (options.isEmpty()) { |
| 160 | 157 | log.error("下拉选项为空,不创建"); |
| 161 | 158 | return; |
| ... | ... | @@ -213,15 +210,16 @@ public class CostFeeController{ |
| 213 | 210 | // 创建下拉框(作用范围:startRow ~ 1000行) |
| 214 | 211 | // ============================================== |
| 215 | 212 | CellRangeAddressList regions = new CellRangeAddressList(startRow, endRow, targetCol, targetCol); |
| 216 | - XSSFDataValidationHelper helper = new XSSFDataValidationHelper(sheet); | |
| 217 | - XSSFDataValidationConstraint constraint = (XSSFDataValidationConstraint) helper.createExplicitListConstraint( | |
| 213 | + DataValidationHelper helper = sheet.getDataValidationHelper(); | |
| 214 | + DataValidationConstraint constraint = helper.createExplicitListConstraint( | |
| 218 | 215 | options.toArray(new String[0]) |
| 219 | 216 | ); |
| 220 | - XSSFDataValidation validation = (XSSFDataValidation) helper.createValidation(constraint, regions); | |
| 221 | - | |
| 217 | + DataValidation validation = helper.createValidation(constraint, regions); | |
| 222 | 218 | // 下拉框基础配置 |
| 223 | 219 | validation.setEmptyCellAllowed(true); |
| 224 | - validation.setSuppressDropDownArrow(true); | |
| 220 | + validation.setSuppressDropDownArrow(true); // 显示箭头 | |
| 221 | + validation.setShowErrorBox(true); | |
| 222 | + validation.setShowPromptBox(true); // 启用点击弹出提示 | |
| 225 | 223 | sheet.addValidationData(validation); |
| 226 | 224 | |
| 227 | 225 | log.info("【成功】为列{}添加下拉并赋值,行{}~{},选项数:{}", | ... | ... |