代码语言:java复制若依导出模板,设置动态下拉框,根据数据库数据
public void downloadImportTemplate(HttpServletResponse response) throws Exception {
List<String> nameList = new ArrayList<>();
nameList.add("aaa");
if(CollectionUtils.isEmpty(nameList)){
throw new ServiceException("数据为空");
}
//动态设置一级下拉框
ExcelUtil<ImportBO> util = new ExcelUtil<>(ImportBO.class);
Class<ImportBO> clazz = util.clazz;
Field field = clazz.getDeclaredField("tier1ChannelsName");
//@Excel注解
Excel excelInterface = field.getAnnotation(Excel.class);
InvocationHandler h = Proxy.getInvocationHandler(excelInterface);
// 获取 AnnotationInvocationHandler 的 memberValues 字段
Field hField = h.getClass().getDeclaredField("memberValues");
// 因为字段是 private 修饰,所以要打开权限
hField.setAccessible(true);
// 获取 memberValues
Map<String, Object> memberValues = (Map<String, Object>) hField.get(h);
String[] comboArray = new String[nameList.size()];
for (int i = 0; i < nameList.size(); i ) {
comboArray[i] = nameList.get(i);
}
memberValues.put("combo", comboArray);
util.importTemplateExcel(response, "数据");
}
/**
* 名称集合
*/
@Excel(name = "名称", combo={""})
private String customName;