From ec3dfe53ae729bf6adf18c469415f79e7a9f03b7 Mon Sep 17 00:00:00 2001 From: walon Date: Fri, 13 Aug 2021 15:35:45 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91=E8=B0=83?= =?UTF-8?q?=E6=95=B4excel=E5=A4=9A=E8=A1=8C=E8=AE=B0=E5=BD=95=E7=9A=84?= =?UTF-8?q?=E5=88=A4=E5=AE=9A=E6=96=B9=E5=BC=8F=E3=80=82=E5=AF=B9=E4=BA=8E?= =?UTF-8?q?=E9=99=A4=E4=BA=86=E5=A4=9A=E8=A1=8C=E5=AD=97=E6=AE=B5=E4=BB=A5?= =?UTF-8?q?=E5=A4=96=E7=9A=84=E5=AD=97=E6=AE=B5=EF=BC=8C=E6=96=B0=E8=A1=8C?= =?UTF-8?q?=E5=85=A8=E7=A9=BA=E6=88=96=E8=80=85=E4=B8=8E=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E8=A1=8C=E7=9B=B8=E5=BA=94=E5=8D=95=E5=85=83=E6=A0=BC=E5=80=BC?= =?UTF-8?q?=E5=AE=8C=E5=85=A8=E7=9B=B8=E5=90=8C=EF=BC=8C=E5=88=99=E5=88=A4?= =?UTF-8?q?=E5=AE=9A=E8=AF=A5=E8=A1=8C=E5=B1=9E=E4=BA=8E=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Source/DataSources/Excel/Sheet.cs | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/src/Luban.Job.Cfg/Source/DataSources/Excel/Sheet.cs b/src/Luban.Job.Cfg/Source/DataSources/Excel/Sheet.cs index f87717a..8fe6300 100644 --- a/src/Luban.Job.Cfg/Source/DataSources/Excel/Sheet.cs +++ b/src/Luban.Job.Cfg/Source/DataSources/Excel/Sheet.cs @@ -129,12 +129,16 @@ namespace Luban.Job.Cfg.DataSources.Excel { continue; } - // 如果非多行数据全空,说明该行属于多行数据 + // 如果非多行数据全空,或者跟记录第一行完全相同说明该行属于多行数据 if (notMultiRowFields.All(f => { var fieldTitle = title.SubTitles[f.Name]; return Sheet.IsBlankRow(row, fieldTitle.FromIndex, fieldTitle.ToIndex); - })) + }) || (recordRows != null && notMultiRowFields.All(f => + { + var fieldTitle = title.SubTitles[f.Name]; + return Sheet.IsSameRow(row, recordRows[0], fieldTitle.FromIndex, fieldTitle.ToIndex); + }))) { if (recordRows == null) { @@ -202,7 +206,7 @@ namespace Luban.Job.Cfg.DataSources.Excel { if (Titles.TryGetValue(name, out var title)) { - CheckEmptySinceSecondRow(name, title.FromIndex, title.ToIndex); + // CheckEmptySinceSecondRow(name, title.FromIndex, title.ToIndex); var es = new ExcelStream(Rows[0], title.FromIndex, title.ToIndex, sep, namedMode); return es; } @@ -607,6 +611,41 @@ namespace Luban.Job.Cfg.DataSources.Excel return true; } + private static bool IsSameRow(List row1, List row2, int fromIndex, int toIndex) + { + if (row2.Count < toIndex - 1) + { + return false; + } + for (int i = Math.Max(1, fromIndex), n = Math.Min(toIndex, row1.Count - 1); i <= n; i++) + { + var v1 = row1[i].Value; + var v2 = row2[i].Value; + if (v1 != v2) + { + if (v1 == null) + { + if (!(v2 is string s && string.IsNullOrWhiteSpace(s))) + { + return false; + } + } + else if (v2 == null) + { + if (!(v1 is string s && string.IsNullOrWhiteSpace(s))) + { + return false; + } + } + else + { + return v1.ToString() == v2.ToString(); + } + } + } + return true; + } + public IEnumerable ReadMulti(TBean type) { foreach (var recordNamedRow in NamedRow.CreateMultiRowNamedRow(this._rowColumns, this._rootTitle, type))