电子表格(飞书/Excel)空行未过滤,导致转 Markdown 后产生大量仅含空表格行的拆分文档
问题描述
Excel、飞书电子表格默认会带有大量空白行(格式/格式刷常把使用区域撑到几百上千行,实际只有前几行有数据)。这些资源导入 OpenViking 转成 Markdown 后,全空行未被过滤;当表格超过拆分阈值被按行切分时,会产生多个"表头 + 成片空表格行"的 md 分片,污染检索结果、浪费存储与 embedding 开销。
注意:纯空白行不会单独成段(MarkdownParser 切分时会 strip),真正产生垃圾分片的是表格中的空行——它们在 Markdown 中形如 | | | |,是合法表格行,会被表格拆分逻辑一视同仁地打包。
复现
- 准备一个飞书电子表格 / xlsx:前 3 行有数据,但使用区域有数百行空行;
ov add-resource导入;- 表格超过 token 阈值被按行拆分后,产物中出现仅含表头和空表格行的 md 分片。
根因分析(main 分支源码)
-
飞书电子表格主导入路径不过滤空行
openviking/parse/accessors/feishu_accessor.py_parse_sheets(约 L2918)通过_read_sheet_range读回原始单元格(空单元格即空字符串)后,直接调用format_table_to_markdown(rows, has_header=True)(约 L2971),中间没有任何全空行过滤;- 文件中只有
_trim_empty_columns(约 L2908,删除"每行都为空"的尾部列),没有对应的_trim_empty_rows;且_trim_empty_columns仅在文档内嵌 sheet 路径(_embedded_sheet_to_markdown,约 L2904)被调用,主导入路径连列裁剪都未使用。 - 文档内嵌普通表格(
_docx_table_to_markdown类逻辑,约 L2800-L2826)同样直接format_table_to_markdown,无空行过滤。
-
本地 Excel(AnyDoc 路径)不做清洗
openviking/parse/parsers/anydoc.py:AnyDoc 转出的 Markdown 原样传入MarkdownParser.parse_content,中间没有去除空表格行的步骤。 -
表格按行拆分保留空行
openviking/parse/parsers/markdown.py的_split_markdown_table_by_rows(约 L756)按整行切分超大表格并重复表头,对空表格行不做识别,导致尾部分片只有表头 + 空行。
期望行为
- 在转 Markdown 前(飞书
format_table_to_markdown调用前、AnyDoc 转换产物上)剔除"所有单元格均为空白"的行,至少去除数据区尾部的全空行; - 中间的空行可能有分隔语义,是否保留建议做成可配置项;
- 可选:在
_split_markdown_table_by_rows中跳过全空表格行,避免空行触发/占据拆分分片。
临时规避
- 导入前在源表中整行删除尾部空白行(不是清空内容);
- 导入时使用
parse_mode="no_split"避免表格被拆分。
环境
- OpenViking 版本:5.0.1
- 部署方式:docker
另外加要给补充,飞书导入表格强制列宽对齐产生大量冗余空格,浪费 token(建议输出紧凑 Markdown 表格或提供配置开关)
I reproduced trailing empty spreadsheet rows producing content-free Markdown chunks. I would like to address the typed-table boundary in format_table_to_markdown(): remove trailing blank data rows while preserving internal blank rows, entirely empty tables, caller inputs, and the original column count.
This is adjacent to but independent of #5740, which compacts formatter padding and restores header repetition. The proposed change does not modify Markdown parsing. AnyDoc output that is already Markdown remains outside this scope.
AI-assisted local validation used the real formatter and MarkdownParser modules from main 2260f6899e882a8d7f693cca4dd8559dfc66b8cf, with existing local dependencies: 8 failed / 9 passed before the fix; 17 passed afterward. Controls include literal pipe lines in indented/unclosed fenced code, 0/False, escaped pipes, HTML entities, and ragged columns. This was component validation, not a complete current-main environment or live Feishu/AnyDoc integration test.
Would maintainers accept this focused scope for a PR?
I reproduced trailing empty spreadsheet rows producing content-free Markdown chunks. I would like to address the typed-table boundary in format_table_to_markdown(): remove trailing blank data rows while preserving internal blank rows, entirely empty tables, caller inputs, and the original column count.
This is adjacent to but independent of #5740, which compacts formatter padding and restores header repetition. The proposed change does not modify Markdown parsing. AnyDoc output that is already Markdown remains outside this scope.
AI-assisted local validation used the real formatter and MarkdownParser modules from main 2260f6899e882a8d7f693cca4dd8559dfc66b8cf, with existing local dependencies: 8 failed / 9 passed before the fix; 17 passed afterward. Controls include literal pipe lines in indented/unclosed fenced code, 0/False, escaped pipes, HTML entities, and ragged columns. This was component validation, not a complete current-main environment or live Feishu/AnyDoc integration test.
Would maintainers accept this focused scope for a PR?