[opt] 优化excel中填写bool类型数据,可以用 true|yes|y|1表示true,用 false|no|n|0表示false

main
walon 2022-12-07 19:28:46 +08:00
parent 2962b6a1bf
commit d0587324f5
3 changed files with 22 additions and 9 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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();