Skip to content

feat: add -sp flag to skip sheets without A1-cell marker#8

Merged
0x5143 merged 9 commits into
masterfrom
feat/sheet-name-filter
May 17, 2026
Merged

feat: add -sp flag to skip sheets without A1-cell marker#8
0x5143 merged 9 commits into
masterfrom
feat/sheet-name-filter

Conversation

@0x5143
Copy link
Copy Markdown
Contributor

@0x5143 0x5143 commented May 17, 2026

问题

xlsm 文件内通常含多个 Sheet(策划注释表、文本表、枚举参考表等),这些非 DataTables 格式的 Sheet 被尝试解析时会抛出 FormatException: 数据列名称不合法

解决方案

新增 -sp <marker> CLI 参数。逻辑:

过滤依据:Sheet 的第一行第一个单元格(A1) 的值是否以 marker 开头。

  • 是 → 导出该 Sheet
  • 否 → 静默跳过

关键约束

  • Sheet 名称不做任何改变
  • 生成的 C# 类名(由 SheetName 决定)不做任何剥离或修改
  • 策划只需在目标 Sheet 的 A1 填入标记(如 DTGen),其余 Sheet 无需改名

用法示例

# 只处理 A1 以 "DTGen" 开头的 Sheet
dotnet dtgen -i ./tables -patterns "*.xlsm" -co ./Generated -do ./DataTables \
             -n MyGame.DataTables -p DT -t SERVER -sp DTGen

变更范围

  • DataTableGenerator.csValidSheet 方法改为检查 A1 单元格;移除旧的 Sheet 名前缀剥离代码
  • Program.cs:更新 -sp 参数的 XML 文档注释

0x5143 added 4 commits May 17, 2026 11:31
Add optional `sheetNameMarker` parameter to `GenerateFile` / `GenerateExcel`.

When non-empty:
- Only sheets whose names start with the marker are processed.
- The marker prefix (plus any leading `_`, `-`, or space) is stripped
  from the sheet name before it becomes the generated class name.
  e.g. marker="DTGen", sheet="DTGenHeroConfig" → class "HeroConfig"

This lets projects keep many auxiliary sheets (enums, text tables,
reference data) in the same workbook without polluting the code-gen
output. Sheets without the marker are silently skipped rather than
generating a parse error.
Both ExportAll (default command) and ExportOne (data command) now accept
`-sp <marker>`. When provided, only sheets whose names start with the
marker are exported, and the marker is stripped when generating the
class name.
Previously the -sp marker was matched against the sheet NAME, which
required renaming sheets (e.g. "导出" → "DTGenHeroConfig"). This is
incompatible with existing naming conventions.

New behaviour: when -sp <marker> is provided, ValidSheet checks the
value of the first cell in the first physical row (A1). If that value
does not start with the marker, the sheet is silently skipped.

- Sheet names and generated class names are unchanged
- The marker cell (A1) already exists in the sheet — no schema changes
- Sheets without the marker (text tables, enum refs, history tabs, etc.)
  are skipped without causing FormatException errors
@0x5143 0x5143 changed the title feat: add -sp sheetNameMarker to filter sheets by name prefix feat: add -sp flag to skip sheets without A1-cell marker May 17, 2026
0x5143 and others added 5 commits May 17, 2026 11:51
After ParseSheetInfoRow, if DataSetType is still empty (meaning DTGen=
was never set in A1), CreateGenerationContext returns immediately.
This prevents RowTableParser from throwing FormatException on
non-DataTables sheets like text tables, enum refs, etc.

The -sp CLI flag is now redundant and will be removed.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@0x5143 0x5143 merged commit f2384c8 into master May 17, 2026
3 checks passed
@0x5143 0x5143 deleted the feat/sheet-name-filter branch May 17, 2026 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant