【特性】支持 [xxx, xxx] 这种格式来标识一个占据多列的字段,方便csv这种不支持多列合并的格式表达多列字段

main
walon 2021-12-10 16:32:57 +08:00
parent e650ff6fe6
commit fb000e400c
1 changed files with 35 additions and 6 deletions

View File

@ -240,7 +240,35 @@ namespace Luban.Job.Cfg.DataSources.Excel
}
var (titleName, tags) = ParseNameAndMetaAttrs(nameAndAttrs);
if (title.SubTitles.TryGetValue(titleName, out var subTitle))
Title subTitle;
if (titleName.StartsWith('['))
{
int startIndex = i;
titleName = titleName.Substring(1);
bool findEndPair = false;
for (++i; i <= title.ToIndex; i++)
{
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;
}
if (!findEndPair)
{
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)
{
@ -252,6 +280,7 @@ namespace Luban.Job.Cfg.DataSources.Excel
}
}
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);