diff --git a/src/Luban.Job.Cfg/Source/DataCreators/SheetDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/SheetDataCreator.cs index e9da915..34f4e95 100644 --- a/src/Luban.Job.Cfg/Source/DataCreators/SheetDataCreator.cs +++ b/src/Luban.Job.Cfg/Source/DataCreators/SheetDataCreator.cs @@ -399,27 +399,38 @@ namespace Luban.Job.Cfg.DataCreators return datas; } - public DType Accept(TArray type, Sheet sheet, TitleRow row) + private List ReadCollectionDatas(TType elementType, Sheet sheet, TitleRow row) { - //string sep = DataUtil.GetSep(type); - if (row.Row != null) { - var s = row.AsStream(DataUtil.GetTypeSep(type.ElementType)); - return new DArray(type, ReadList(type.ElementType, s)); + var s = row.AsStream(DataUtil.GetTypeSep(elementType)); + return ReadList(elementType, s); } else if (row.Rows != null) { - var s = row.AsMultiRowStream(DataUtil.GetTypeSep(type.ElementType)); - return new DArray(type, ReadList(type.ElementType, s)); + var s = row.AsMultiRowStream(DataUtil.GetTypeSep(elementType)); + return ReadList(elementType, s); } else if (row.Fields != null) { - throw new Exception($"array 不支持 子字段. 忘记将字段设为多行模式? {row.SelfTitle.Name} => *{row.SelfTitle.Name}"); + //throw new Exception($"array 不支持 子字段. 忘记将字段设为多行模式? {row.SelfTitle.Name} => *{row.SelfTitle.Name}"); + + var datas = new List(row.Fields.Count); + var sortedFields = row.Fields.Values.ToList(); + sortedFields.Sort((a, b) => a.SelfTitle.FromIndex - b.SelfTitle.FromIndex); + foreach (var field in sortedFields) + { + if (field.IsBlank) + { + continue; + } + datas.Add(elementType.Apply(this, sheet, field)); + } + return datas; } else if (row.Elements != null) { - return new DArray(type, row.Elements.Select(e => type.ElementType.Apply(this, sheet, e)).ToList()); + return row.Elements.Select(e => elementType.Apply(this, sheet, e)).ToList(); } else { @@ -427,56 +438,20 @@ namespace Luban.Job.Cfg.DataCreators } } + public DType Accept(TArray type, Sheet sheet, TitleRow row) + { + //string sep = DataUtil.GetSep(type); + return new DArray(type, ReadCollectionDatas(type.ElementType, sheet, row)); + } + public DType Accept(TList type, Sheet sheet, TitleRow row) { - if (row.Row != null) - { - var s = row.AsStream(DataUtil.GetTypeSep(type.ElementType)); - return new DList(type, ReadList(type.ElementType, s)); - } - else if (row.Rows != null) - { - var s = row.AsMultiRowStream(DataUtil.GetTypeSep(type.ElementType)); - return new DList(type, ReadList(type.ElementType, s)); - } - else if (row.Fields != null) - { - throw new Exception($"list 不支持 子字段. 忘记将字段设为多行模式? {row.SelfTitle.Name} => *{row.SelfTitle.Name}"); - } - else if (row.Elements != null) - { - return new DList(type, row.Elements.Select(e => type.ElementType.Apply(this, sheet, e)).ToList()); - } - else - { - throw new Exception(); - } + return new DList(type, ReadCollectionDatas(type.ElementType, sheet, row)); } public DType Accept(TSet type, Sheet sheet, TitleRow row) { - if (row.Row != null) - { - var s = row.AsStream(DataUtil.GetTypeSep(type.ElementType)); - return new DSet(type, ReadList(type.ElementType, s)); - } - else if (row.Rows != null) - { - var s = row.AsMultiRowStream(DataUtil.GetTypeSep(type.ElementType)); - return new DSet(type, ReadList(type.ElementType, s)); - } - else if (row.Fields != null) - { - throw new Exception($"set 不支持 子字段"); - } - else if (row.Elements != null) - { - throw new NotSupportedException(); - } - else - { - throw new Exception(); - } + return new DSet(type, ReadCollectionDatas(type.ElementType, sheet, row)); } public DType Accept(TMap type, Sheet sheet, TitleRow row) diff --git a/src/Luban.Job.Cfg/Source/DataSources/Excel/Title.cs b/src/Luban.Job.Cfg/Source/DataSources/Excel/Title.cs index 97dd062..d57a09b 100644 --- a/src/Luban.Job.Cfg/Source/DataSources/Excel/Title.cs +++ b/src/Luban.Job.Cfg/Source/DataSources/Excel/Title.cs @@ -45,7 +45,7 @@ namespace Luban.Job.Cfg.DataSources.Excel { if (!SubTitles.TryAdd(title.Name, title)) { - throw new Exception($"标题:{title.Name} 重复"); + throw new Exception($"列:{title.Name} 重复"); } SubTitleList.Add(title); } diff --git a/src/Luban.Job.Cfg/Source/DataSources/Excel/TitleRow.cs b/src/Luban.Job.Cfg/Source/DataSources/Excel/TitleRow.cs index 672e2bb..f2df3b8 100644 --- a/src/Luban.Job.Cfg/Source/DataSources/Excel/TitleRow.cs +++ b/src/Luban.Job.Cfg/Source/DataSources/Excel/TitleRow.cs @@ -62,6 +62,30 @@ namespace Luban.Job.Cfg.DataSources.Excel } } + public bool IsBlank + { + get + { + if (Row != null) + { + return Sheet.IsBlankRow(Row, SelfTitle.FromIndex, SelfTitle.ToIndex); + } + if (Rows != null) + { + return Sheet.IsBlankRow(Rows[0], SelfTitle.FromIndex, SelfTitle.ToIndex); + } + if (Fields != null) + { + return Fields.Values.All(f => f.IsBlank); + } + if (Elements != null) + { + return Elements.All(e => e.IsBlank); + } + throw new Exception(); + } + } + public ExcelStream AsStream(string sep) { if (string.IsNullOrEmpty(SelfTitle.Sep))