Skip to content

fix(knowledge): retain embedded images when parsing Excel files - #2401

Open
yaojin3616 wants to merge 1 commit into
mainfrom
fix/excel-multi-sheet-image-parse
Open

fix(knowledge): retain embedded images when parsing Excel files#2401
yaojin3616 wants to merge 1 commit into
mainfrom
fix/excel-multi-sheet-image-parse

Conversation

@yaojin3616

Copy link
Copy Markdown
Collaborator

Summary

Gitee issue IKC7BU: 带图片的多 sheet Excel 文件解析后图片内容全部丢失(解析格式与原文件不一致)。

Root cause: md_from_excel (the fixed Excel → markdown parse path for xlsx/xls in the knowledge pipeline) only exported cell values. Every embedded image was silently dropped; a sheet whose content was only an image was skipped as "empty".

Changes:

  • md_from_excel.py: extract each sheet's embedded images (openpyxl) into the loader's flat image staging dir; reference them from the generated markdown at the image's anchor row. Images anchored beyond the data range ride on the last chunk; image-only sheets now emit their images instead of being dropped.
  • ExcelLoader / XinChuangFormatterLoader (et format): honor the file rule's retain_images flag, rewrite local image refs to final MinIO URLs via the existing rewrite_local_image_refs contract — ImageUploadTransformer uploads the staged bytes unchanged (both Knowledge and Preview pipelines already wire it for excel).
  • Legacy handler() path (patch_130) keeps its previous behavior.

Test plan

  • New regression tests test/knowledge/test_md_from_excel_images.py (3 passed): anchor-row extraction, multi-sheet markdown keeps image refs, image-only sheet retained, legacy no-image_dir behavior unchanged
  • Chunked parse (30 rows / 10 per chunk) places the image in the chunk containing its anchor row
  • CI

Refs: Gitee issue IKC7BU (https://gitee.com/Data-Elem_1/dashboard/issues?id=IKC7BU)

Multi-sheet Excel files with embedded images lost every image during
knowledge parsing: md_from_excel exported only cell values, so
image-bearing sheets lost their visual content and image-only sheets
were dropped entirely.

- extract per-sheet embedded images (openpyxl) into the loader's flat
  image staging dir and reference them from the generated markdown at
  their anchor row (images beyond the data range ride on the last
  chunk; image-only sheets now emit their images instead of being
  skipped)
- ExcelLoader / XinChuangFormatterLoader honor the file rule's
  retain_images flag and rewrite local image refs to the final MinIO
  URLs; ImageUploadTransformer picks the staged bytes up unchanged
- legacy handler() path (patch_130) keeps its previous behavior
- add regression tests under test/knowledge/

Refs: Gitee issue IKC7BU (带图片的多sheet文件解析,解析格式不对)
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