diff --git a/src/Luban.Job.Cfg/Source/DataCreators/ExcelNamedRowDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/ExcelNamedRowDataCreator.cs index 304bb33..ea4c8b1 100644 --- a/src/Luban.Job.Cfg/Source/DataCreators/ExcelNamedRowDataCreator.cs +++ b/src/Luban.Job.Cfg/Source/DataCreators/ExcelNamedRowDataCreator.cs @@ -287,9 +287,46 @@ namespace Luban.Job.Cfg.DataCreators throw new NotSupportedException(); } + + private bool TryCreateColumnStream(Sheet.NamedRow x, Sheet.Title title, out ExcelStream stream) + { + var cells = new List(); + for (int i = title.FromIndex; i <= title.ToIndex; i++) + { + foreach (var row in x.Rows) + { + if (row.Count > i) + { + var value = row[i].Value; + if (!(value == null || (value is string s && string.IsNullOrEmpty(s)))) + { + cells.Add(row[i]); + } + } + } + } + if (cells.Count > 0) + { + stream = new ExcelStream(cells, 0, cells.Count - 1, "", false); + return true; + } + stream = null; + return false; + } + public DType Accept(TMap type, Sheet.NamedRow x, bool multirow, bool nullable) { - throw new NotSupportedException(); + var map = new Dictionary(); + foreach (var (key, keyTitle) in x.Titles) + { + if (TryCreateColumnStream(x, keyTitle, out var stream)) + { + var keyData = type.KeyType.Apply(StringDataCreator.Ins, key); + var valueData = type.ValueType.Apply(ExcelDataCreator.Ins, null, stream, DefAssembly.LocalAssebmly); + map.Add(keyData, valueData); + } + } + return new DMap(type, map); } public DType Accept(TVector2 type, Sheet.NamedRow x, bool multirow, bool nullable) diff --git a/src/Luban.Job.Cfg/Source/DataSources/Excel/Sheet.cs b/src/Luban.Job.Cfg/Source/DataSources/Excel/Sheet.cs index f096ea8..b297452 100644 --- a/src/Luban.Job.Cfg/Source/DataSources/Excel/Sheet.cs +++ b/src/Luban.Job.Cfg/Source/DataSources/Excel/Sheet.cs @@ -123,7 +123,7 @@ namespace Luban.Job.Cfg.DataSources.Excel } else { - List notMultiRowFields = bean.Bean.HierarchyFields.Select(f => (DefField)f).Where(f => !f.IsMultiRow).ToList(); + List notMultiRowFields = bean.Bean.HierarchyFields.Select(f => (DefField)f).Where(f => !f.IsMultiRow && f.IsRowOrient).ToList(); List> recordRows = null; foreach (var row in rows) { @@ -262,7 +262,8 @@ namespace Luban.Job.Cfg.DataSources.Excel { if (!IsBlankColumn(Rows, i)) { - yield return new ExcelStream(Rows.Select(r => r[i]).ToList(), 0, Rows.Count - 1, sep, false); + var cells = Rows.Where(r => r.Count > i).Select(r => r[i]).Where(v => !(v.Value == null || (v.Value is string s && string.IsNullOrEmpty(s)))).ToList(); + yield return new ExcelStream(cells, 0, cells.Count - 1, sep, false); } } } @@ -661,6 +662,10 @@ namespace Luban.Job.Cfg.DataSources.Excel { foreach (List row in rows) { + if (column >= row.Count) + { + continue; + } var v = row[column].Value; if (v != null && !(v is string s && string.IsNullOrEmpty(s))) { diff --git a/src/Luban.Job.Cfg/Source/RawDefs/CfgField.cs b/src/Luban.Job.Cfg/Source/RawDefs/CfgField.cs index 58b0583..bdebf75 100644 --- a/src/Luban.Job.Cfg/Source/RawDefs/CfgField.cs +++ b/src/Luban.Job.Cfg/Source/RawDefs/CfgField.cs @@ -25,7 +25,7 @@ namespace Luban.Job.Cfg.RawDefs public string DefaultValue { get; set; } = ""; - public bool IsRowOrient { get; set; } = false; + public bool IsRowOrient { get; set; } = true; public List Groups { get; set; } = new List();