跳到主要内容

从工作表中提取工作表 Excel

PDF4me 提取工作表 是一个 REST 从中提取选定工作表的端点 Excel 工作簿并将其作为新的工作簿内容返回。 POST 文件为 Base64office/ApiV2Excel/ExcelExtractWorksheet给工作表命名或列出它们的从 0 开始的索引,然后保存解码后的结果。如果不发送任何选择器,则会提取所有工作表。

此端点的作用

按工作表拆分工作簿。您只需发送整个文件一次,并描述要拆分哪些工作表即可。 将工作表提取到 Excel 操作:可按精确的标签名称(区分大小写)、从 0 开始的索引或两者同时使用(取其并集)。它取代了手动右键单击、移动或复制的操作,适用于报表分发、团队拆分以及任何收件人只能看到自己工作表的流程。

相关博客文章
目前尚无关于此功能的博客文章——敬请期待。
在此期间,您可以浏览 PDF4me 博客,查看适用于各平台的教程和工作流程。
访问博客

验证您的身份 API 要求

每一个 PDF4me REST 通话必须包含您的 API 关键在于 Authorization 请求头设置为基本身份验证。请从开发者控制面板获取或轮换您的密钥。

端点

POSToffice/ApiV2Excel/ExcelExtractWorksheet

您不容错过的重要事实

名称 + 索引 = 并集,两者都不是 = 全部
提供 工作表名称工作表索引或者两者都选;任何符合任一列表的工作表都会被提取。如果两者都不选,则会提取所有工作表,这通常不是您想要的定向拆分方式。
索引从 0 开始,名称区分大小写。
索引 0 是第一个工作表标签。名称与实际标签大小写不同的标签不会匹配任何内容,因此输出中意外缺少工作表通常意味着大小写不匹配,而不是其他原因。 API 错误。
办公室 API 家庭,不同的路径形状
Excel 运营持续进行 office/ApiV2Excel/ 在同一主机上,而不是在……之下 /api/v2/主体也是嵌套的:一个动作对象(将工作表提取到 Excel 操作)而不是平坦的根域。

HTTP 设置

方法: POST
URL https://api.pdf4me.com/office/ApiV2Excel/ExcelExtractWorksheet
内容类型: application/json
Authorization 基本 <您的 PDF4me API 键>

回答是 JSON检查 success 然后,举旗。 Base64-解码返回的工作簿内容并将其保存 .xlsx 扩大。

提取的是名称表还是索引表?

选择操作是声明式的。您无需重新排序或循环;只需描述一次目标工作表,引擎就会根据工作簿进行解析。

名称与索引你发送提取出的物质
仅姓名"worksheetNames": ["Sheet1", "Summary"]标签页名称完全匹配(区分大小写)的工作表
仅索引"worksheetIndexes": [0, 2]位于这些从 0 开始的位置的表格
两个都名称 + 索引联盟:任何符合任一列表的内容
两者都不{} 动作对象工作簿中的每一张工作表

API 身体场

范围必需的类型它的作用例子
documentRequiredobjectDocument reference carrying Name, the source Excel filename with its extension.{ "Name": "data.xlsx" }
docContentRequiredstringBase64-encoded bytes of the source workbook.UEsDBBQABgAIAAAA...
extractWorksheetToExcelActionRequiredobjectAction configuration object. Holds the worksheet selectors below; send it even when empty to extract all sheets.{ "worksheetNames": [...] }
worksheetNamesConditionalstring[]Inside the action object. Exact, case-sensitive sheet tab names to extract. Combine with indexes for a union.["Sheet1", "Summary"]
worksheetIndexesConditionalint[]Inside the action object. 0-based sheet positions to extract. Combine with names for a union.[0, 2]
cultureNameOptionalstringInside the action object. Culture code applied during processing.en-US

示例有效载荷

按名称提取两张表格

{
"document": { "Name": "data.xlsx" },
"docContent": "UEsDBBQABgAIAAAA...",
"extractWorksheetToExcelAction": {
"worksheetNames": ["Sheet1", "Summary"]
}
}

按 0 基索引提取

{
"document": { "Name": "data.xlsx" },
"docContent": "UEsDBBQABgAIAAAA...",
"extractWorksheetToExcelAction": {
"worksheetIndexes": [0, 2]
}
}

邮递员收款小贴士

Headers
Content-Type: application/json + Authorization: Basic <apiKey>.
Body
raw JSON. Note the nesting: selectors go INSIDE extractWorksheetToExcelAction, not at the root.
Response
JSON with a success flag and Base64 workbook content. Decode the content before saving as .xlsx.
Sheet names
Copy tab names from Excel exactly. Case matters, and a non-matching name is skipped silently rather than raising an error.

curl 示例

curl -X POST https://api.pdf4me.com/office/ApiV2Excel/ExcelExtractWorksheet \
-H "Content-Type: application/json" \
-H "Authorization: Basic YOUR_API_KEY" \
-d '{
"document": { "Name": "data.xlsx" },
"docContent": "'"$(base64 -w 0 data.xlsx)"'",
"extractWorksheetToExcelAction": {
"worksheetNames": ["Summary"]
}
}' \
--output response.json

什么 API 返回?

A JSON 结果描述了提取过程并将新工作簿内容打包成…… Base64

场地类型它包含什么
document / documentsString (Base64) / ArrayThe extracted workbook content. A single extraction returns one document; multi-sheet extraction can return an array, so handle both shapes.
fileNameStringOutput filename for the extracted workbook.
successBooleantrue when extraction succeeded. Check this before decoding content.
errorMessageStringPopulated when success is false; explains what went wrong.

代码示例

Excel 办公终端尚未包含在按百分比计费的范围内。language 示例文件夹;示例存储库包含每个请求使用的请求模式。 PDF4me 端点系列:

常问问题

How do I extract a single sheet from an Excel workbook?+
Send the workbook as Base64 in docContent and put the sheet name in extractWorksheetToExcelAction.worksheetNames, for example ["Summary"]. The API returns a new workbook containing only that sheet.
What happens if I provide both worksheetNames and worksheetIndexes?+
The selections combine as a union: any sheet matching either a listed name or a listed index is extracted. If you provide neither field, every worksheet in the workbook is extracted.
Are worksheet indexes 0-based or 1-based?+
0-based. Index 0 is the first worksheet, index 1 the second, and so on. This matches the PDF4me Extract Worksheets documentation across platforms.
Are worksheet names case-sensitive?+
Yes. The name must match the sheet tab exactly, including case. A name that does not match any sheet is simply not extracted, so an unexpectedly missing sheet usually means a case mismatch rather than an API error.
Why is this endpoint not under /api/v2/?+
Excel operations belong to the PDF4me office API family, addressed as office/ApiV2Excel/ plus the action name on the same api.pdf4me.com host, with the same Basic Authorization header.
Does extraction change the source workbook?+
No. The source file you send is only read. The extracted sheets are returned as new workbook content in the response; nothing is written back to your original.
Can I extract every sheet into its own file?+
Sending an empty action object extracts all worksheets. For strict one-file-per-sheet splits, iterate your sheet list and call the endpoint once per name; each call returns a workbook containing just that sheet.

为什么要通过以下方式提取工作表 API 而不是手动操作?

手动路线是 在以下位置移动或复制工作表 Excel右键单击标签,选择“移动或复制”,勾选“创建副本”,另存为新文件,对每个工作表、每个工作簿、每个报告周期重复此操作。 API 它将循环替换为每次拆分一次的确定性请求,这正是工作簿按计划到达且拆分结果会提供给其他系统时所需要的。输出保持标准格式。 办公室开放 XML 工作簿 ExcelLibreOffice 和 Google Sheets 都打开了。

相关行动

在其他平台上执行相同的任务

获取帮助