Skip to content

bug: get_tables 的 NxM header 只取首列欄數 — 不規則表格靜默誤導座標 #157

Description

@kiki830621

Problem

get_tables 的表格摘要頭 [i] NxM tableM(欄數)只反映第一列。真實 Word 文件的表格常是不規則的(各列 <w:gridSpan> 不同、或本來就有不同數量的 <w:tc>),此時 M 與實際可定址的欄索引不符,而輸出沒有任何跡象顯示這件事。

後果是靜默的錯誤定址:讀 NxM 推論「這個表格只有 M 欄」→ 對 col >= M 的欄位不去嘗試,或把座標算錯。

Reproduction

兩份真實表單,get_tables 的 header 與 search_text 實測座標對照:

表單 A(送件核對單)

get_tables → [0] 20x1 table

但實測:

search_text("備齊")   → Table 0, row 3, col 2
search_text("REC確認") → Table 0, row 3, col 4

→ header 說 1 欄,實際最寬 5 欄。

表單 B(繳款資料表)

get_tables → [0] 10x2 table

但實測:

search_text("收件人姓名") → Table 0, row 6, col 0
search_text("聯絡電話")   → Table 0, row 6, col 2

→ header 說 2 欄,該列實際 4 欄。

兩份的共同形狀:前幾列是跨欄的標題列(1 欄),本體列才展開成多欄;NxM 取到的是第一列

Expected

至少要能從輸出看出表格是不規則的。幾個可行的方向(擇一即可):

  • header 改用最大欄數,並在不規則時標注,例如 [0] 20x1..5 table (ragged)
  • 每列摘要各自帶欄數
  • 回傳結構化的 per-row cell count,讓 caller 自己判斷

Actual

NxM 無條件取第一列的 <w:tc> 數,不規則性不可見。

Impact

任何依 get_tables 規劃寫入座標的流程都可能靜默寫錯格子。下游 rec-fill 因此把規則寫成「座標一律以 search_text 逐格實測為準,不得採信 get_tables header 的欄數」——但那是繞過,不是修好;新的 caller 仍會踩。

相關

  • 下游脈絡:PsychQuant/ntu-claude-plugins#16

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions