Repository navigation
Conversation
split_excel_by_column 生成的输出文件有两个问题: 1. .xlsx 分支:openpyxl.Workbook() 会自带一个空白 sheet,之后每个分组又 调用 create_sheet,导致输出文件的第一页永远是一个没有内容的 Sheet。 2. 分组值被直接当作 sheet 名,而 Excel 限制 sheet 名最长 31 个字符且不能 包含 : \ / ? * [ ]。按日期(2026/10/22)、文件路径、网址这类列拆分时: - .xlsx 分支抛 ValueError: Invalid character / found in sheet title - .xls 分支抛 Exception: invalid worksheet name 整个拆分直接失败。 修复: - .xlsx 分支复用 openpyxl 自带的空白 sheet 承载第一个分组,输出不再有空白页 - 新增 _to_valid_sheet_name(),替换非法字符、截断到 31 字符并保证不重名, 两个分支统一使用 新增 tests/test_code/test_excel_split_sheet_name.py(7 个用例), 修复前全部失败,修复后全部通过。
CoderWanFeng
pushed a commit
that referenced
this pull request
Oct 25, 2026
Owner
|
感谢贡献!🎉 你的修复已合入 合入 commit: 验证情况:
亮点:
期待你继续贡献! |
CoderWanFeng
pushed a commit
that referenced
this pull request
Oct 26, 2026
发布 1.1.0:合入 #183 / #184 / #185 三个 PR,以及自 1.0.6 以来的全部修复。 主要内容: - feat(cli): 第一波 CLI 实现 —— `po` 命令 (#184) - feat(contributors): 5 个 Excel 数据核对与整理方法 (#185) - feat(contributor): batch_rename_by_excel (#183) - fix(excel): 拆分时保留 0 值 (#180) - fix(finance): t0 的 Decimal/float TypeError (#181) - fix(excel): 拆分输出工作簿有效性 (#182) - 及其他 1.0.6 以来的修复与文档更新 - 合并 main 独有的 #141 / #155 版本号: 1.0.6 → 1.1.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
office/lib/excel/SplitExcel.py生成的拆分结果文件有两个问题。1.
.xlsx输出永远多一个空白 Sheetgenerate_xlsx()里openpyxl.Workbook()会自带一个空白 sheet,之后每个分组又create_sheet():按「城市」列拆分的实际输出(
split_excel_by_column(demo.xlsx, 2)):2. 分组值直接当 sheet 名,遇到非法字符或超长值直接崩溃
Excel 限制 sheet 名最长 31 个字符,且不能包含
: \ / ? * [ ]。而分组值来自单元格内容,按日期、文件路径、网址这类列拆分时会命中:另外
generate_xlsx()是在process_xlsx()的try/except之外调用的,异常会直接抛给调用方。修复
.xlsx分支复用 openpyxl 自带的空白 sheet 承载第一个分组,输出不再有空白页_to_valid_sheet_name():替换非法字符、截断到 31 字符、截断后重名时追加序号;.xls和.xlsx两个分支统一使用修复后同样的输入:
测试
新增
tests/test_code/test_excel_split_sheet_name.py,7 个用例覆盖:空白默认 sheet、非法字符替换、.xls超长名、31 字符截断、截断后重名、空值兜底。修复前 7 个用例全部失败,修复后全部通过;
tests/test_code/test_excel_split_wrapper.py原有的 2 个用例仍然通过。说明
拆分时表头行会被当作一个分组(示例里出现名为「城市」的 sheet)。这属于原有行为,本 PR 未改动,以免影响已有调用方;如果希望表头不参与分组,可以另开一个 PR。