【修复】修复识别非顶层多行记录的bug

main
walon 2021-10-25 17:30:03 +08:00
parent dd582a37ee
commit 79d684dca4
4 changed files with 34 additions and 4 deletions

View File

@ -69,6 +69,26 @@ namespace Luban.Job.Cfg.DataSources.Excel
return new TitleRow(title, fields); return new TitleRow(title, fields);
} }
private static bool IsMultiRowsExtendRow(List<Cell> row, Title title)
{
if (title.HasSubTitle)
{
foreach (var t in title.SubTitleList)
{
if (!t.SelfMultiRows && !IsMultiRowsExtendRow(row, t))
{
return false;
}
}
//return title.SubTitleList.All(t => t.SelfMultiRows || IsMultiRowsExtendRow(row, t));
return true;
}
else
{
return IsBlankRow(row, title.FromIndex, title.ToIndex);
}
}
private IEnumerable<List<List<Cell>>> SplitRows(Title title, List<List<Cell>> rows) private IEnumerable<List<List<Cell>>> SplitRows(Title title, List<List<Cell>> rows)
{ {
List<List<Cell>> oneRecordRows = null; List<List<Cell>> oneRecordRows = null;
@ -84,7 +104,7 @@ namespace Luban.Job.Cfg.DataSources.Excel
} }
else else
{ {
if (title.SubTitleList.All(t => t.SelfMultiRows || IsBlankRow(row, t.FromIndex, t.ToIndex))) if (IsMultiRowsExtendRow(row, title))
{ {
oneRecordRows.Add(row); oneRecordRows.Add(row);
} }

View File

@ -421,7 +421,7 @@ namespace Luban.Job.Cfg.DataSources.Excel
var fields = new Dictionary<string, FieldInfo>(); var fields = new Dictionary<string, FieldInfo>();
foreach (var subTitle in title.SubTitleList) foreach (var subTitle in title.SubTitleList)
{ {
if (subTitle.Name.StartsWith("__")) if (!DefUtil.IsNormalFieldName(subTitle.Name))
{ {
continue; continue;
} }

View File

@ -1,4 +1,5 @@
using Bright.Collections; using Bright.Collections;
using Luban.Job.Common.Utils;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -72,8 +73,12 @@ namespace Luban.Job.Cfg.DataSources.Excel
{ {
if (Root) if (Root)
{ {
// 第一个字段一般为key为了避免失误将空单元格当作key=0的数据默认非空 var firstField = SubTitleList.FirstOrDefault(f => DefUtil.IsNormalFieldName(f.Name));
SubTitleList[0].Tags.TryAdd("non_empty", "1"); if (firstField != null)
{
// 第一个字段一般为key为了避免失误将空单元格当作key=0的数据默认非空
firstField.Tags.TryAdd("non_empty", "1");
}
} }
foreach (var sub in SubTitleList) foreach (var sub in SubTitleList)
{ {

View File

@ -81,5 +81,10 @@ namespace Luban.Job.Common.Utils
} }
} }
} }
public static bool IsNormalFieldName(string name)
{
return !name.StartsWith("__");
}
} }
} }