Skip to content
LlamaParse 文档版本 跟随上游 源快照 85a12df8 更新于 2026-10-16

Parse 会连同单元格结构一起恢复表格,并同时返回它的多种形式:既出现在该页的 markdown 里(竖线表或 HTML),也作为 items 树里一个类型为 table 的条目,带 rows、csv、html 与 md 四种表示。你要哪种格式由几个输出选项决定,还可以让 Parse 把每张表格写进一个 XLSX 工作簿。

什么时候用它

  • 财务报表、10-K、业绩演示与审计报告 —— 跨很多页、有大量表格。
  • 含合并表头的表格 —— markdown 竖线表无法表达。
  • 跨页接续的表格 —— 你希望它们作为一张表返回。
  • 无框线或轻描边框的表格 —— 基于文本的解析器会漏掉。
  • 要把表格数据载入 pandas、数仓或电子表格,而不是当散文来读。

以文字为主、表格简单的文档选 cost_effective;有真正的表格与扫描页的选 agentic;密集的财报与复杂表格选 agentic_plus。fast 档不调用任何 AI 模型,因此当表格有合并单元格、跨页接续或缺少框线时,请选 cost_effective 或更高档位。

选项

选项类型默认值作用
output_options.markdown.tables.output_tables_as_markdownboolean未设true 输出 markdown 竖线表;false 保留 HTML <table> 标签。竖线表更简单但表达不了合并单元格;HTML 可以,用 colspan。
output_options.markdown.tables.merge_continued_tablesboolean未设把跨多页的一张表合并为一张。合并后的表出现在第一页,并带 merged_from_pages 元数据。
output_options.markdown.tables.compact_markdown_tablesboolean未设去掉 markdown 表格单元格内的空白填充。
output_options.markdown.tables.markdown_table_multiline_separatorstring未设markdown 表格里多行单元格内容的分隔符,例如用 "<br>" 保留换行,或用 " " 拼接。
output_options.tables_as_spreadsheet.enableboolean未设额外把每张表格写入一个 XLSX 文件,每张表一个 sheet。用 expand=["xlsx_content_metadata"] 取回。
output_options.tables_as_spreadsheet.guess_sheet_namebooleantrue用表格的表头与周边文字来命名 sheet,而不是 Table_1。
processing_options.aggressive_table_extractionboolean未设更努力地寻找表格边界,包括没有可见框线的表格。可能带来误检。
processing_options.disable_heuristicsboolean未设当带框线抽取与超长表格的自适应处理给出错误结果时,把它们关掉。
output_options.granular_bboxes"cell"、"line"、"word" 的数组[]为表格的每个单元格附加边界框,用于高亮。见版面与边界框。

示例

从快速上手 下载那份报告:

终端窗口

curl -fL -o executive-summary-2024.pdf https://fiscal.treasury.gov/system/files/files/reports-statements/financial-report/2024/executive-summary-2024.pdf

上传它、跑一个 Parse 任务,从 items 树里收集每张表格,并用它们的 csv 载入 pandas:

import io

import pandas as pd
from llama_cloud import LlamaCloud

client = LlamaCloud()  # reads LLAMA_CLOUD_API_KEY from the environment

file = client.files.create(file="./executive-summary-2024.pdf", purpose="parse")

result = client.parsing.parse(
    file_id=file.id,
    tier="agentic",
    version="latest",
    output_options={"markdown": {"tables": {"merge_continued_tables": True}}},
    expand=["markdown", "items"],
)

tables = [
    (page.page_number, item)
    for page in result.items.pages
    if page.success  # a failed page carries no items
    for item in page.items
    if item.type == "table"
]
print(f"Found {len(tables)} tables across {len(result.items.pages)} pages")

for page_number, table in tables:
    df = pd.read_csv(io.StringIO(table.csv))
    print(f"page {page_number}: {len(df)} rows x {len(df.columns)} cols")

你会拿到什么

在该页的 markdown 里,对快速上手 那份报告做一次默认的 agentic 解析会返回 HTML 形式的汇总表,并保留其合并的表头行:

<table>
  <thead>
    <tr><th colspan="3">Financial Measures (Dollars in Billions):</th></tr>
    <tr><th></th><th>2024</th><th>2023*</th></tr>
  </thead>
  <tbody>
    <tr><td>Gross Costs</td><td>$ (7,772.2)</td><td>$ (7,661.7)</td></tr>
    <tr><td>Less: Earned Revenue</td><td>$ 652.9</td><td>$ 539.5</td></tr>
  </tbody>
</table>

在 items 树里,同一张表是一个带类型的条目,数据有四种形态:

{
  "type": "table",
  "rows": [["Financial Measures (Dollars in Billions):", "2024", "2023*"], ["Gross Costs", "$ (7,772.2)", "$ (7,661.7)"]],
  "csv": "Financial Measures (Dollars in Billions):,2024,2023*\nGross Costs,$ (7,772.2),$ (7,661.7)",
  "html": "<table>...</table>",
  "md": "| Financial Measures (Dollars in Billions): | 2024 | 2023* |\n|---|---|---|..."
}

rows 是列表的列表,csv 可以直接交给 pandas.read_csv,html 与 md 则可直接展示。启用 tables_as_spreadsheet 后,expand=["xlsx_content_metadata"] 会附上该工作簿的预签名下载地址。

另请参阅

BytesRouter 是社区翻译站点,所有译文仅供参考,一切以官方英文原文为准。