//动态设置用户类型下拉框
        ExcelUtil<ImportBO> util = new ExcelUtil<>(ImportBO.class);
        Class<ImportBO> clazz = util.clazz;
        Field field = clazz.getDeclaredField("userType");
        //@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);
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
     /**
     * 用户类型集合
     */
    @Excel(name = "用户类型", combo={""})
    private String userType;
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.