Skip to content
Merged
4 changes: 2 additions & 2 deletions src/DataTables.Generator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class MyCommands
/// <param name="searchPattern">-patterns, Input file wildcard.</param>
/// <param name="codeOutputDir">-co, Code output file directory.</param>
/// <param name="dataOutputDir">-do, Data output file directory.</param>
/// <param name="importNamespaces">-ins, Import namespaces of generated files, split with char '&' for multiple namespaces.</param>
/// <param name="importNamespaces">-ins, Import namespaces of generated files, split with char '&amp;' for multiple namespaces.</param>
/// <param name="usingNamespace">-n, Namespace of generated files.</param>
/// <param name="prefixClassName">-p, Prefix of class names.</param>
/// <param name="filterColumnTags">-t, Tags of filter columns.</param>
Expand Down Expand Up @@ -84,7 +84,7 @@ public async Task ExportAll(
/// <param name="inputDirectories">-i, Input file directory(search recursive).</param>
/// <param name="searchPattern">-patterns, Input file wildcard.</param>
/// <param name="dataOutputDir">-do, Data output file directory.</param>
/// <param name="importNamespaces">-ins, Import namespaces of generated files, split with char '&' for multiple namespaces.</param>
/// <param name="importNamespaces">-ins, Import namespaces of generated files, split with char '&amp;' for multiple namespaces.</param>
/// <param name="usingNamespace">-n, Namespace of generated files.</param>
/// <param name="prefixClassName">-p, Prefix of class names.</param>
/// <param name="filterColumnTags">-t, Tags of filter columns.</param>
Expand Down
13 changes: 10 additions & 3 deletions src/DataTables.GeneratorCore/DataTableGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ private async Task GenerateExcel(string filePath, string usingNamespace, string
var genSw = System.Diagnostics.Stopwatch.StartNew();
try
{
// 初始化GenerateContext
// 仍使用 NPOI sheet;解析器内部已使用抽象层
// 初始化GenerateContext;若 A1 未声明 DTGen= 则内部静默返回
processor.CreateGenerationContext(sheet);
if (!processor.ValidateGenerationContext())
{
Expand Down Expand Up @@ -260,7 +259,15 @@ private async Task GenerateExcel(string filePath, string usingNamespace, string
}
}

// 检验是否过滤该Sheet
/// <summary>
/// 检验是否处理该 Sheet。
/// 规则:
/// 1. sheet 为 null → 跳过
/// 2. Sheet 名称以 '#' 开头 → 跳过(注释 Sheet)
///
/// 注意:A1 是否声明 DTGen= 的检查在 DataTableProcessor.CreateGenerationContext 内部完成,
/// 未声明时会静默返回,不会抛出 FormatException。
/// </summary>
private static bool ValidSheet(ISheet? sheet)
{
if (sheet == null)
Expand Down
6 changes: 6 additions & 0 deletions src/DataTables.GeneratorCore/DataTableProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public void CreateGenerationContext(ISheet sheet)
var headerRow = sheet.GetRow(headerRowIndex);
ParseSheetInfoRow(GetCellString(headerRow.GetCell(headerRow.FirstCellNum)));

// A1 未声明 DTGen=,该 Sheet 不是 DataTables 格式,静默跳过
if (string.IsNullOrEmpty(m_Context.DataSetType))
{
return;
}

// 按模式选择解析器
ITableSchemaParser parser = m_Context.DataSetType == "matrix"
? new MatrixTableParser()
Expand Down
9 changes: 7 additions & 2 deletions src/DataTables.GeneratorCore/GenerationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ public class GenerationContext

public string DataRowClassPrefix { get; set; } = string.Empty;

public string DataSetType { get; set; } = "table";
/// <summary>
/// 表结构类型:table / matrix / column。
/// 默认为空字符串;仅在 A1 单元格中声明了 DTGen= 时才会被赋值。
/// CreateGenerationContext 解析完 A1 后会检查此值是否为空,若为空则认为该 Sheet
/// 不是 DataTables 格式并跳过后续解析。
/// </summary>
public string DataSetType { get; set; } = string.Empty;

public string Title { get; set; } = string.Empty;

Expand Down Expand Up @@ -252,4 +258,3 @@ public class XField(int index)
/// </summary>
public bool IsTagFiltered { get; set; }
}

Loading