【优化】允许自由组织##field行的位置,不必强制从第2行开始。

main
walon 2021-10-28 10:40:55 +08:00
parent 8082c8f87f
commit e7c03419a5
1 changed files with 30 additions and 6 deletions

View File

@ -96,6 +96,30 @@ namespace Luban.Job.Cfg.DataSources.Excel
return rootTitle; return rootTitle;
} }
private static bool TryFindNextSubFieldRowIndex(List<List<Cell>> cells, int startRowIndex, out int rowIndex)
{
for (int i = startRowIndex; i < cells.Count; i++)
{
var row = cells[i];
if (row.Count == 0)
{
break;
}
string rowTag = row[0].Value?.ToString() ?? "";
if (rowTag.StartsWith("##field"))
{
rowIndex = i;
return true;
}
else if (!rowTag.StartsWith("##"))
{
break;
}
}
rowIndex = 0;
return false;
}
private static bool IsIgnoreTitle(string title) private static bool IsIgnoreTitle(string title)
{ {
#if !LUBAN_LITE #if !LUBAN_LITE
@ -134,9 +158,9 @@ namespace Luban.Job.Cfg.DataSources.Excel
return (titleName, tags); return (titleName, tags);
} }
private static void ParseSubTitles(Title title, List<List<Cell>> cells, CellRange[] mergeCells, bool orientRow, int curDepth) private static void ParseSubTitles(Title title, List<List<Cell>> cells, CellRange[] mergeCells, bool orientRow, int excelRowIndex)
{ {
var rowIndex = curDepth - 1; var rowIndex = excelRowIndex - 1;
var titleRow = cells[rowIndex]; var titleRow = cells[rowIndex];
if (mergeCells != null) if (mergeCells != null)
{ {
@ -177,9 +201,9 @@ namespace Luban.Job.Cfg.DataSources.Excel
continue; continue;
} }
if (curDepth < cells.Count && IsSubFieldRow(cells[curDepth])) if (excelRowIndex < cells.Count && TryFindNextSubFieldRowIndex(cells, excelRowIndex, out int nextRowIndex))
{ {
ParseSubTitles(subTitle, cells, mergeCells, orientRow, curDepth + 1); ParseSubTitles(subTitle, cells, mergeCells, orientRow, nextRowIndex + 1);
} }
title.AddSubTitle(subTitle); title.AddSubTitle(subTitle);
@ -207,9 +231,9 @@ namespace Luban.Job.Cfg.DataSources.Excel
} }
} }
subTitle = new Title() { Name = titleName, Tags = tags, FromIndex = i, ToIndex = i }; subTitle = new Title() { Name = titleName, Tags = tags, FromIndex = i, ToIndex = i };
if (curDepth < cells.Count && IsSubFieldRow(cells[curDepth])) if (excelRowIndex < cells.Count && TryFindNextSubFieldRowIndex(cells, excelRowIndex, out int nextRowIndex))
{ {
ParseSubTitles(subTitle, cells, mergeCells, orientRow, curDepth + 1); ParseSubTitles(subTitle, cells, mergeCells, orientRow, nextRowIndex + 1);
} }
title.AddSubTitle(subTitle); title.AddSubTitle(subTitle);
} }