技能标识:polaris-datainsight-doc-extract
Extract structured data from Office documents (DOCX, PPTX, XLSX, HWP, HWPX) using the Polaris AI DataInsight Doc Extract API. Use when the user wants to parse, analyze, or extract text, tables, charts, images, or shapes from document files. Invoke this skill whenever the user mentions extracting content from Word, PowerPoint, Excel, HWP, or HWPX files, wants to parse document structure, needs to convert document data for RAG pipelines, or asks about reading tables, charts, or text from Office-fo
使用 Polaris AI DataInsight 文档提取 API,从 Word、PowerPoint、Excel、HWP 和 HWPX 文件中提取文本、图片、表格、图表、形状、公式等内容,并以结构化的 unifiedSchema JSON 格式返回所有内容。单次 API 调用即可获取完整的文档结构,无需手动解析。
获取 API 密钥:在 https://datainsight.polarisoffice.com 注册并生成您的 API 密钥。
身份验证:在每个请求中将 API 密钥作为标头包含。
标头: x-po-di-apikey: $POLARISDATAINSIGHTAPI_KEY
设置环境变量:
bash
export POLARISDATAINSIGHTAPI_KEY=your-api-key-here
| 项目 | 限制 |
|---|---|
| 支持的格式 | HWP、HWPX、DOCX、PPTX、XLSX |
| 最大文件大小 |
端点:
POST https://datainsight-api.polarisoffice.com/api/v1/datainsight/doc-extract
使用 Python 提取文档:
python
import requests
import json
import zipfile
import io
def extractdocument(filepath: str, api_key: str) -> dict:
with open(file_path, rb) as f:
response = requests.post(
https://datainsight-api.polarisoffice.com/api/v1/datainsight/doc-extract,
headers={x-po-di-apikey: api_key},
files={file: f}
)
if response.status_code != 200:
raise Exception(fAPI 错误: {response.status_code} - {response.text})
# 响应是一个 ZIP 文件
zip_buffer = io.BytesIO(response.content)
with zipfile.ZipFile(zip_buffer) as z:
json_files = [name for name in z.namelist() if name.endswith(.json)]
if json_files:
with z.open(json_files[0]) as jf:
return json.load(jf)
raise Exception(ZIP 中未找到 JSON)
使用 curl 提取:
bash
curl -X POST https://datainsight-api.polarisoffice.com/api/v1/datainsight/doc-extract \
-H x-po-di-apikey: $POLARISDATAINSIGHTAPI_KEY \
-F file=@example.docx \
--output result.zip
unzip result.zip -d result/
cat result/*.json | python -m json.tool
根节点:
json
{
docName: sample.docx,
totalPages: 3,
pages: [ ... ]
}
页面 (pages[]):
json
{
pageNum: 1,
pageWidth: 595.3,
pageHeight: 842.0,
extractionSummary: {
text: 5, image: 2, table: 1, chart: 1
},
elements: [ ... ]
}
元素类型 (elements[].type):
| 类型 | 描述 |
|---|---|
| text | 文本块 |
| image |
通用元素结构:
json
{
type: text,
id: te1,
boundaryBox: { left: 40, top: 80, right: 300, bottom: 120 },
content: { text: 此处为正文内容 }
}
表格内容:
json
{
content: {
html:
图表内容:
json
{
content: {
chart_type: column,
title: 年度销售对比,
xaxislabels: [Q1, Q2, Q3, Q4],
series_names: [2023, 2024],
series_values: [[100, 200, 150, 300], [120, 220, 180, 320]],
csv: Quarter,2023,2024\nQ1,100,120\nQ2,200,220
}
}
提取所有文本:
python
def getalltext(schema: dict) -> str:
texts = []
for page in schema.get(pages, []):
for el in page.get(elements, []):
if el[type] == text and el.get(content, {}).get(text):
texts.append(el[content][text])
return \n.join(texts)
提取表格为 CSV:
python
def gettablesas_csv(schema: dict) -> list:
tables = []
for page in schema.get(pages, []):
for el in page.get(elements, []):
if el[type] == table:
csv_data = el.get(content, {}).get(csv, )
if csv_data:
tables.append(csv_data)
return tables
生成 RAG 分块:
python
def makeragchunks(schema: dict) -> list:
chunks = []
doc_name = schema.get(docName, )
for page in schema.get(pages, []):
for el in page.get(elements, []):
text = el.get(content, {}).get(text) or el.get(content, {}).get(csv) or
if text.strip():
chunks.append({
source: doc_name,
page: page[pageNum],
type: el[type],
text: text.strip()
})
return chunks
用户: 从这份 DOCX 报告中提取所有表格数据为 CSV。
输出:
python
import os
schema = extractdocument(report.docx, os.environ[POLARISDATAINSIGHTAPIKEY])
tables = gettablesas_csv(schema)
for i, csv_data in enumerate(tables):
print(f=== 表格 {i+1} ===)
print(csv_data)
=== 表格 1 ===
Quarter,Revenue,Cost
Q1,1200,800
Q2,1500,900
=== 表格 2 ===
Item,Amount
Labor,500
Operations,300
灵感来源: Polaris Office DataInsight API 文档和工作流。
以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:
帮我安装 SkillHub 和 polaris-datainsight-doc-extract-1776279424 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 polaris-datainsight-doc-extract-1776279424 技能
skillhub install polaris-datainsight-doc-extract-1776279424
文件大小: 4.33 KB | 发布时间: 2026-4-16 16:36