2.15下拉生成
@Excel 加入 addressList 是否生成下拉的选项,默认false
目前下拉只支持replace和dict两个取值地方生成
根据对应的值生成相应的下拉,xssf下拉rowMax = 100万,hssf下拉maxRow=65536,从数据第一行开始生成,使用方法也比较简单
@Excel(name = "名字")
private String name;
@Excel(name = "性别")
private Sex sex;
@Excel(name = "B站登记", dict = "level", addressList = true)
private int bilibili;
@Excel(name = "状态", replace = {"初始化_0", "正常_1", "注销_2"}, addressList = true)
private String status;
只需要在原有代码的基础上设置addressList =true就可以了
replace就是生成[“初始化”, “正常”, “注销”]
dict 加入了一个新的方法
* 返回字典所有值
* key: dictKey
* value: dictValue
* @param dict 字典Key
* @return
*/
default public List<Map> getList(String dict) {
return null;
}
看下demo,字典的demo和实际不同,仅供参考
/**
* 模拟使用,生产请用真实字典
*
* @author jueyue on 20-4-26.
*/
public class ExcelDiceAddressListHandlerImpl implements IExcelDictHandler {
/**
* 返回字典所有值
* key: dictKey
*
* @param dict 字典Key
* @return
*/
@Override
public List<Map> getList(String dict) {
List<Map> list = new ArrayList<>();
Map<String, String> dictMap = new HashMap<>();
dictMap.put("dictKey", "0");
dictMap.put("dictValue", "严重瞌睡");
list.add(dictMap);
dictMap = new HashMap<>();
dictMap.put("dictKey", "1");
dictMap.put("dictValue", "小B");
list.add(dictMap);
dictMap = new HashMap<>();
dictMap.put("dictKey", "1");
dictMap.put("dictValue", "深度富有");
list.add(dictMap);
return list;
}
@Override
public String toName(String dict, Object obj, String name, Object value) {
if ("level".equals(dict)) {
int level = Integer.parseInt(value.toString());
switch (level) {
case 1:
return "小B";
case 0:
return "严重瞌睡";
case 2:
return "深度富有";
}
}
return null;
}
@Override
public String toValue(String dict, Object obj, String name, Object value) {
if ("level".equals(dict)) {
int level = Integer.parseInt(value.toString());
switch (level) {
case 1:
return "小B";
case 0:
return "严重瞌睡";
case 2:
return "深度富有";
}
}
return null;
}
}
生成就没啥可写的了,生成效果
作者:悟耘信息 创建时间:2020-04-27 14:26
更新时间:2022-09-04 22:15
更新时间:2022-09-04 22:15