Extract Worksheets from Excel
PDF4me Extract Worksheets is a REST endpoint that pulls selected sheets out of an Excel workbook and returns them as new workbook content. POST the file as Base64 to office/ApiV2Excel/ExcelExtractWorksheet, name the sheets or list their 0-based indexes, and save the decoded result. Send neither selector and every worksheet is extracted.
Splits a workbook by sheet. You send the whole file once and describe which sheets you want inside extractWorksheetToExcelAction: by exact tab name (case-sensitive), by 0-based index, or both at once (the union is taken). It replaces the manual right-click, Move or Copy routine for report distribution, per-team splits, and any workflow where recipients should only see their own sheet.
Authenticating Your API Request
Every PDF4me REST call must include your API key in the Authorization header as Basic auth. Get or rotate your key from the developer dashboard.
Endpoint
office/ApiV2Excel/ExcelExtractWorksheetImportant Facts You Should Not Miss
worksheetNames, worksheetIndexes, or both; any sheet matching either list is extracted. Omit both and ALL worksheets are extracted, which is rarely what you want for a targeted split.office/ApiV2Excel/ on the same host, not under /api/v2/. The body is also nested: an action object (extractWorksheetToExcelAction) instead of flat root fields.HTTP setup
Method: POST
URL: https://api.pdf4me.com/office/ApiV2Excel/ExcelExtractWorksheet
Content-Type: application/json
Authorization: Basic <your PDF4me API key>
The response is JSON: check the success flag, then Base64-decode the returned workbook content and save it with an .xlsx extension.
Which sheets get extracted: names vs indexes?
Selection is declarative. You never reorder or loop; you describe the target sheets once and the engine resolves them against the workbook.
| Names vs indexes | You send | What is extracted |
|---|---|---|
| Names only | "worksheetNames": ["Sheet1", "Summary"] | Sheets whose tab name matches exactly (case-sensitive) |
| Indexes only | "worksheetIndexes": [0, 2] | Sheets at those 0-based positions |
| Both | names + indexes | The union: anything matching either list |
| Neither | {} action object | Every worksheet in the workbook |
API body fields
| Parameter | Required | Type | What it does | Example |
|---|---|---|---|---|
document | Required | object | Document reference carrying Name, the source Excel filename with its extension. | { "Name": "data.xlsx" } |
docContent | Required | string | Base64-encoded bytes of the source workbook. | UEsDBBQABgAIAAAA... |
extractWorksheetToExcelAction | Required | object | Action configuration object. Holds the worksheet selectors below; send it even when empty to extract all sheets. | { "worksheetNames": [...] } |
worksheetNames | Conditional | string[] | Inside the action object. Exact, case-sensitive sheet tab names to extract. Combine with indexes for a union. | ["Sheet1", "Summary"] |
worksheetIndexes | Conditional | int[] | Inside the action object. 0-based sheet positions to extract. Combine with names for a union. | [0, 2] |
cultureName | Optional | string | Inside the action object. Culture code applied during processing. | en-US |
Sample payloads
Extract two sheets by name
{
"document": { "Name": "data.xlsx" },
"docContent": "UEsDBBQABgAIAAAA...",
"extractWorksheetToExcelAction": {
"worksheetNames": ["Sheet1", "Summary"]
}
}
Extract by 0-based index
{
"document": { "Name": "data.xlsx" },
"docContent": "UEsDBBQABgAIAAAA...",
"extractWorksheetToExcelAction": {
"worksheetIndexes": [0, 2]
}
}
Postman collection tips
curl example
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
What does the API return?
A JSON result describing the extraction and carrying the new workbook content as Base64.
| Field | Type | What it contains |
|---|---|---|
document / documents | String (Base64) / Array | The extracted workbook content. A single extraction returns one document; multi-sheet extraction can return an array, so handle both shapes. |
fileName | String | Output filename for the extracted workbook. |
success | Boolean | true when extraction succeeded. Check this before decoding content. |
errorMessage | String | Populated when success is false; explains what went wrong. |
Code samples
Excel office endpoints are not yet covered by per-language sample folders; the samples repository carries the request pattern used by every PDF4me endpoint family:
FAQ
Why extract worksheets via API instead of manually?
The manual route is Move or copy worksheets in Excel: right-click the tab, Move or Copy, tick Create a copy, save as a new file, repeat per sheet, per workbook, per reporting cycle. The API replaces that loop with one deterministic request per split, which is what you want when the workbook arrives on a schedule and the split feeds other systems. The output stays a standard Office Open XML workbook that Excel, LibreOffice, and Google Sheets all open.