From fb000e400cf2c415c467b72f8c8fdf38ae3a3cd0 Mon Sep 17 00:00:00 2001 From: walon Date: Fri, 10 Dec 2021 16:32:57 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=89=B9=E6=80=A7=E3=80=91=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20[xxx,=20=20=20xxx]=20=E8=BF=99=E7=A7=8D=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E6=9D=A5=E6=A0=87=E8=AF=86=E4=B8=80=E4=B8=AA=E5=8D=A0?= =?UTF-8?q?=E6=8D=AE=E5=A4=9A=E5=88=97=E7=9A=84=E5=AD=97=E6=AE=B5=EF=BC=8C?= =?UTF-8?q?=E6=96=B9=E4=BE=BFcsv=E8=BF=99=E7=A7=8D=E4=B8=8D=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=A4=9A=E5=88=97=E5=90=88=E5=B9=B6=E7=9A=84=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E8=A1=A8=E8=BE=BE=E5=A4=9A=E5=88=97=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Source/DataSources/Excel/SheetLoadUtil.cs | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/Luban.Job.Cfg/Source/DataSources/Excel/SheetLoadUtil.cs b/src/Luban.Job.Cfg/Source/DataSources/Excel/SheetLoadUtil.cs index 92e58f0..0ada759 100644 --- a/src/Luban.Job.Cfg/Source/DataSources/Excel/SheetLoadUtil.cs +++ b/src/Luban.Job.Cfg/Source/DataSources/Excel/SheetLoadUtil.cs @@ -240,18 +240,47 @@ namespace Luban.Job.Cfg.DataSources.Excel } var (titleName, tags) = ParseNameAndMetaAttrs(nameAndAttrs); - if (title.SubTitles.TryGetValue(titleName, out var subTitle)) + Title subTitle; + if (titleName.StartsWith('[')) { - if (subTitle.FromIndex != i) + int startIndex = i; + titleName = titleName.Substring(1); + bool findEndPair = false; + for (++i; i <= title.ToIndex; i++) { - throw new Exception($"列:{titleName} 重复"); + var endNamePair = titleRow[i].Value?.ToString()?.Trim(); + if (string.IsNullOrEmpty(endNamePair)) + { + continue; + } + if (!endNamePair.EndsWith(']') || endNamePair[0..^1] != titleName) + { + throw new Exception($"列:'[{titleName}' 后第一个有效列必须为匹配 '{titleName}]',却发现:'{endNamePair}'"); + } + findEndPair = true; + break; } - else + if (!findEndPair) { - continue; + throw new Exception($"列:'[{titleName}' 未找到结束匹配列 '{titleName}]'"); } + subTitle = new Title() { Name = titleName, Tags = tags, FromIndex = startIndex, ToIndex = i }; + } + else + { + if (title.SubTitles.TryGetValue(titleName, out subTitle)) + { + if (subTitle.FromIndex != i) + { + throw new Exception($"列:{titleName} 重复"); + } + else + { + continue; + } + } + subTitle = new Title() { Name = titleName, Tags = tags, FromIndex = i, ToIndex = i }; } - subTitle = new Title() { Name = titleName, Tags = tags, FromIndex = i, ToIndex = i }; if (excelRowIndex < cells.Count && TryFindNextSubFieldRowIndex(cells, excelRowIndex, out int nextRowIndex)) { ParseSubTitles(subTitle, cells, mergeCells, orientRow, nextRowIndex + 1);