feat: MIXED 完整段落解析(分割→每段最优解析)
This commit is contained in:
@@ -81,3 +81,58 @@ def test_mixed_sheet_holds_paragraphs():
|
||||
ms = MixedSheet(name="混合", paragraphs=[p1, p2])
|
||||
assert ms.name == "混合"
|
||||
assert [p.kind for p in ms.paragraphs] == ["table", "free_text"]
|
||||
|
||||
|
||||
def test_parse_mixed_sheet_segmented(tmp_path):
|
||||
wb = new_workbook({
|
||||
"混合": [
|
||||
["機能ID", "機能名"],
|
||||
["F101", "社員登録"],
|
||||
["F102", "退職処理"],
|
||||
[],
|
||||
["・改修ポイント:F102 追加バリデーション"],
|
||||
["■対象画面:SC001"],
|
||||
],
|
||||
})
|
||||
path = save_workbook(tmp_path, wb)
|
||||
result = ExcelParser().parse(path)
|
||||
assert result.mixed, "混合 sheet 应产产出 mixed 段落"
|
||||
ms = result.mixed[0]
|
||||
assert ms.name == "混合"
|
||||
kinds = [p.kind for p in ms.paragraphs]
|
||||
assert "table" in kinds and "free_text" in kinds
|
||||
# 表格段无碎片污染:table 段应含 2 数据行,机能ID 首行为 F101
|
||||
tbl = [p.table for p in ms.paragraphs if p.kind == "table"][0]
|
||||
assert tbl is not None and len(tbl.rows) == 2
|
||||
assert tbl.rows[0]["機能ID"].value == "F101"
|
||||
# 自由文本段捕获碎片
|
||||
ft = [p for p in ms.paragraphs if p.kind == "free_text"][0]
|
||||
assert "改修ポイント" in (ft.text or "")
|
||||
|
||||
|
||||
def test_parse_mixed_sheet_formatting_in_mid_segment(tmp_path):
|
||||
# 表格段不在物理行 0(自由文本段在前),数据行 F101 设取消线 —— 锁住 formatting_map 坐标错位
|
||||
from copy import copy
|
||||
from openpyxl import Workbook
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
ws.title = "混合"
|
||||
data = [
|
||||
["■はじめに"], ["前提説明"], [],
|
||||
["機能ID", "機能名"], ["F101", "社員登録"], ["F102", "退職処理"],
|
||||
[], ["・改修ポイント"],
|
||||
]
|
||||
for r, row in enumerate(data, start=1):
|
||||
for c, v in enumerate(row, start=1):
|
||||
if v:
|
||||
ws.cell(row=r, column=c, value=v)
|
||||
font = copy(ws.cell(row=5, column=1).font) # F101 所在物理行(第 5 行)
|
||||
font.strike = True
|
||||
ws.cell(row=5, column=1).font = font
|
||||
path = save_workbook(tmp_path, wb)
|
||||
result = ExcelParser().parse(path)
|
||||
ms = result.mixed[0]
|
||||
tbl = [p.table for p in ms.paragraphs if p.kind == "table"][0]
|
||||
cv = tbl.rows[0]["機能ID"] # F101
|
||||
assert cv.formatting is not None
|
||||
assert cv.formatting.strikethrough is True
|
||||
|
||||
Reference in New Issue
Block a user