Fix parse image in excel as table, the image shows as one column (#17569)

This commit is contained in:
Wang Qi
2026-07-30 17:20:04 +08:00
committed by GitHub
parent 1629357bf7
commit 1667d1495f
2 changed files with 28 additions and 1 deletions

View File

@@ -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)