diff --git a/src/Luban.Job.Cfg/Source/DataCreators/SheetDataCreator.cs b/src/Luban.Job.Cfg/Source/DataCreators/SheetDataCreator.cs index 5d59368..48e8e19 100644 --- a/src/Luban.Job.Cfg/Source/DataCreators/SheetDataCreator.cs +++ b/src/Luban.Job.Cfg/Source/DataCreators/SheetDataCreator.cs @@ -289,9 +289,8 @@ namespace Luban.Job.Cfg.DataCreators } else if (row.Rows != null) { - throw new NotSupportedException(); - //var s = row.AsMultiRowStream(sep); - //return new DArray(type, ReadList(type.ElementType, s)); + var s = row.AsMultiRowConcatStream(sep); + return type.Apply(ExcelStreamDataCreator.Ins, s); } else if (row.Fields != null) { @@ -332,12 +331,11 @@ namespace Luban.Job.Cfg.DataCreators return new DBean(originBean, originBean, CreateBeanFields(originBean, sheet, row)); } - - } else if (row.Elements != null) { - throw new NotSupportedException(); + var s = row.AsMultiRowConcatElements(sep); + return type.Apply(ExcelStreamDataCreator.Ins, s); } else { @@ -345,9 +343,6 @@ namespace Luban.Job.Cfg.DataCreators } } - - - public List ReadList(TType type, ExcelStream stream) { var datas = new List(); diff --git a/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelStream.cs b/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelStream.cs index 708d009..c29b8fd 100644 --- a/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelStream.cs +++ b/src/Luban.Job.Cfg/Source/DataSources/Excel/ExcelStream.cs @@ -108,6 +108,58 @@ namespace Luban.Job.Cfg.DataSources.Excel } } + public ExcelStream(List> rows, int fromIndex, int toIndex, string sep, string overrideDefault) + { + _overrideDefault = overrideDefault; + this._datas = new List(); + if (string.IsNullOrWhiteSpace(sep)) + { + if (string.IsNullOrEmpty(overrideDefault)) + { + foreach (var row in rows) + { + for (int i = fromIndex; i <= toIndex; i++) + { + this._datas.Add(row[i]); + } + } + } + else + { + throw new NotSupportedException("concated multi rows don't support 'default' "); + } + + } + else + { + foreach (var row in rows) + { + for (int i = fromIndex; i <= toIndex; i++) + { + var cell = row[i]; + object d = cell.Value; + if (!IsSkip(d)) + { + if (d is string s) + { + this._datas.AddRange(DataUtil.SplitStringByAnySepChar(s, sep).Select(x => new Cell(cell.Row, cell.Column, x))); + } + else + { + this._datas.Add(cell); + } + } + else if (!string.IsNullOrEmpty(_overrideDefault)) + { + this._datas.Add(new Cell(cell.Row, cell.Column, _overrideDefault)); + } + } + } + } + this._curIndex = 0; + this._toIndex = this._datas.Count - 1; + } + public string First => _datas[_curIndex].Value?.ToString(); public string LastReadDataInfo => _datas[Math.Min(LastReadIndex, _datas.Count - 1)].ToString(); diff --git a/src/Luban.Job.Cfg/Source/DataSources/Excel/SheetLoadUtil.cs b/src/Luban.Job.Cfg/Source/DataSources/Excel/SheetLoadUtil.cs index ab13cf2..7264bef 100644 --- a/src/Luban.Job.Cfg/Source/DataSources/Excel/SheetLoadUtil.cs +++ b/src/Luban.Job.Cfg/Source/DataSources/Excel/SheetLoadUtil.cs @@ -145,6 +145,12 @@ namespace Luban.Job.Cfg.DataSources.Excel string titleName = attrs[0]; var tags = new Dictionary(); + // * 开头的表示是多行 + if (titleName.StartsWith('*')) + { + titleName = titleName.Substring(1); + tags.Add("multi_rows", "1"); + } foreach (var attrPair in attrs.Skip(1)) { var pairs = attrPair.Split('='); diff --git a/src/Luban.Job.Cfg/Source/DataSources/Excel/TitleRow.cs b/src/Luban.Job.Cfg/Source/DataSources/Excel/TitleRow.cs index f52c631..1e3aae9 100644 --- a/src/Luban.Job.Cfg/Source/DataSources/Excel/TitleRow.cs +++ b/src/Luban.Job.Cfg/Source/DataSources/Excel/TitleRow.cs @@ -118,24 +118,19 @@ namespace Luban.Job.Cfg.DataSources.Excel public IEnumerable AsMultiRowStream(string sep) { - //if (Titles.TryGetValue(name, out var title)) - //{ - // if (isRowOrient) - // { - // var totalCells = Rows.SelectMany(r => r.GetRange(title.FromIndex, title.ToIndex - title.FromIndex + 1)) - // .Where(c => c.Value != null && !(c.Value is string s && string.IsNullOrWhiteSpace(s))).ToList(); - // return new ExcelStream(totalCells, 0, totalCells.Count - 1, sep, false); - // } - // else - // { - // throw new NotSupportedException($"bean类型多行数据不支持纵向填写"); - // } - //} - //else - //{ - // throw new Exception($"单元薄 缺失 列:{name},请检查是否写错或者遗漏"); - //} throw new NotSupportedException(); } + + public ExcelStream AsMultiRowConcatStream(string sep) + { + sep = string.IsNullOrEmpty(sep) ? SelfTitle.Sep : sep; + return new ExcelStream(Rows, SelfTitle.FromIndex, SelfTitle.ToIndex, sep, SelfTitle.Default); + } + + public ExcelStream AsMultiRowConcatElements(string sep) + { + sep = string.IsNullOrEmpty(sep) ? SelfTitle.Sep : sep; + return new ExcelStream(Elements.Select(e => e.Row).ToList(), SelfTitle.FromIndex, SelfTitle.ToIndex, sep, SelfTitle.Default); + } } }