[opt] 优化excel中填写bool类型数据,可以用 true|yes|y|1表示true,用 false|no|n|0表示false
parent
2962b6a1bf
commit
d0587324f5
|
|
@ -29,14 +29,7 @@ namespace Luban.Job.Cfg.DataCreators
|
|||
return b;
|
||||
}
|
||||
var s = x.ToString().ToLower().Trim();
|
||||
switch (s)
|
||||
{
|
||||
case "true":
|
||||
case "是": return true;
|
||||
case "false":
|
||||
case "否": return false;
|
||||
default: throw new InvalidExcelDataException($"{s} 不是 bool 类型的值 (true 或 false)");
|
||||
}
|
||||
return DataUtil.ParseExcelBool(s);
|
||||
}
|
||||
|
||||
public DType Accept(TBool type, ExcelStream x)
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ namespace Luban.Job.Cfg.DataCreators
|
|||
{
|
||||
return DBool.ValueOf(v);
|
||||
}
|
||||
return DBool.ValueOf(bool.Parse(x.ToString()));
|
||||
return DBool.ValueOf(DataUtil.ParseExcelBool(x.ToString()));
|
||||
}
|
||||
|
||||
public DType Accept(TByte type, RowColumnSheet sheet, TitleRow row)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Luban.Common.Utils;
|
||||
using Luban.Job.Cfg.DataCreators;
|
||||
using Luban.Job.Cfg.Datas;
|
||||
using Luban.Job.Cfg.DataSources;
|
||||
using Luban.Job.Cfg.Defs;
|
||||
|
|
@ -257,6 +258,25 @@ namespace Luban.Job.Cfg.Utils
|
|||
return defType;
|
||||
}
|
||||
|
||||
public static bool ParseExcelBool(string s)
|
||||
{
|
||||
s = s.ToLower().Trim();
|
||||
switch (s)
|
||||
{
|
||||
case "true":
|
||||
case "是":
|
||||
case "1":
|
||||
case "y":
|
||||
case "yes": return true;
|
||||
case "false":
|
||||
case "否":
|
||||
case "0":
|
||||
case "n":
|
||||
case "no": return false;
|
||||
default: throw new InvalidExcelDataException($"{s} 不是 bool 类型的值 (true|是|1|y|yes 或 false|否|0|n|no)");
|
||||
}
|
||||
}
|
||||
|
||||
//public static string Data2String(DType data)
|
||||
//{
|
||||
// var s = new StringBuilder();
|
||||
|
|
|
|||
Loading…
Reference in New Issue