From 1667d1495f8141114d82a1db96b92e5fa508196b Mon Sep 17 00:00:00 2001 From: Wang Qi Date: Thu, 30 Jul 2026 17:20:04 +0800 Subject: [PATCH] Fix parse image in excel as table, the image shows as one column (#17569) --- rag/app/table.py | 3 ++- .../rag/app/test_table_chunk_column_roles.py | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/rag/app/table.py b/rag/app/table.py index 9a65abb185..bff9bcd613 100644 --- a/rag/app/table.py +++ b/rag/app/table.py @@ -83,7 +83,8 @@ class Excel(ExcelParser): image_descriptions = vision_figure_parser_figure_xlsx_wrapper(images=images, callback=callback, **kwargs) if image_descriptions and len(image_descriptions) == len(images): for i, bf in enumerate(image_descriptions): - images[i]["image_description"] = "\n".join(bf[0][1]) + desc = bf[0][1] + images[i]["image_description"] = "\n".join(desc) if isinstance(desc, list) else str(desc) for img in images: if img["span_type"] == "single_cell" and img.get("image_description"): pending_cell_images.append(img) diff --git a/test/unit_test/rag/app/test_table_chunk_column_roles.py b/test/unit_test/rag/app/test_table_chunk_column_roles.py index dfd1f13316..d9d3d2dc1e 100644 --- a/test/unit_test/rag/app/test_table_chunk_column_roles.py +++ b/test/unit_test/rag/app/test_table_chunk_column_roles.py @@ -20,6 +20,7 @@ from __future__ import annotations import sys +from io import BytesIO from importlib import import_module, reload from unittest.mock import MagicMock, patch @@ -128,6 +129,31 @@ def test_chunk_deduplicates_repeated_column_names(table_module, mock_update_kb: assert args[1]["table_column_names"] == ["name", "name_3", "name_2"] +def test_excel_image_description_string_stays_single_cell(table_module, monkeypatch): + from openpyxl import Workbook + + wb = Workbook() + ws = wb.active + ws.append(["image", "note"]) + ws.append([None, "keep"]) + buf = BytesIO() + wb.save(buf) + + monkeypatch.setattr( + table_module.Excel, + "_extract_images_from_worksheet", + staticmethod( + lambda ws, sheetname=None: [{"sheet": sheetname or ws.title, "image": None, "image_description": "", "row_from": 2, "col_from": 1, "row_to": 2, "col_to": 1, "span_type": "single_cell"}] + ), + ) + monkeypatch.setattr(table_module, "vision_figure_parser_figure_xlsx_wrapper", lambda images, callback=None, **kwargs: [((None, "abcdef"), [(0, 0, 0, 0, 0)])]) + + dfs, tbls = table_module.Excel()("test.xlsx", binary=buf.getvalue(), callback=_noop_callback) + + assert tbls == [] + assert dfs[0].iat[0, 0] == "abcdef" + + def test_chunk_auto_mode_all_columns_in_text_and_stored(table_module, mock_update_kb: MagicMock): parser_config: dict = {} chunks = _run_chunk(table_module, parser_config, mock_update_kb)