fix(rag): ExcelKnowledge._load must handle headerless sheets and multi-sheet workbooks (#3137)

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Andrew Chen
2026-07-16 19:14:50 +08:00
committed by GitHub
parent 7996544a43
commit 4752f9fa8c
2 changed files with 46 additions and 1 deletions

View File

@@ -175,6 +175,7 @@ class ExcelKnowledge(Knowledge):
)
else:
data_rows = unmerged_data
df_start_row_index = 0
logging.info(
f"Sheet '{sheet_name}': No clear header row found. "
f"All rows considered data."
@@ -261,7 +262,7 @@ class ExcelKnowledge(Knowledge):
)
docs.append(doc)
return docs
return docs
@classmethod
def support_chunk_strategy(cls) -> List[ChunkStrategy]:

View File

@@ -0,0 +1,44 @@
import openpyxl
import pytest
from ..excel import ExcelKnowledge
@pytest.fixture
def multi_sheet_xlsx(tmp_path):
path = tmp_path / "multi_sheet.xlsx"
wb = openpyxl.Workbook()
ws1 = wb.active
ws1.title = "Sheet1"
ws1.append(["name", "value"])
ws1.append(["a", 1])
ws2 = wb.create_sheet("Sheet2")
ws2.append(["name", "value"])
ws2.append(["b", 2])
wb.save(path)
return str(path)
@pytest.fixture
def numeric_only_xlsx(tmp_path):
path = tmp_path / "numeric_only.xlsx"
wb = openpyxl.Workbook()
ws = wb.active
ws.title = "NumericSheet"
for r in range(6):
ws.append([r, r + 1, r + 2])
wb.save(path)
return str(path)
def test_load_reads_all_sheets(multi_sheet_xlsx):
knowledge = ExcelKnowledge(file_path=multi_sheet_xlsx)
docs = knowledge._load()
sheets_seen = {doc.metadata["sheet_name"] for doc in docs}
assert sheets_seen == {"Sheet1", "Sheet2"}
def test_load_does_not_crash_without_header_row(numeric_only_xlsx):
knowledge = ExcelKnowledge(file_path=numeric_only_xlsx)
docs = knowledge._load()
assert len(docs) == 6