Skip to main content

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.

What this endpoint does

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.

Related Blog Posts
No blog post yet for this feature — coming soon.
In the meantime, browse the PDF4me blog for tutorials and workflows across every platform.
Visit the blog

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

POSToffice/ApiV2Excel/ExcelExtractWorksheet

Important Facts You Should Not Miss

Names + indexes = union, neither = everything
Provide 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.
Indexes are 0-based, names are case-sensitive
Index 0 is the first sheet tab. A name that differs in capitalization from the real tab silently matches nothing, so an unexpectedly missing sheet in the output usually means a case mismatch, not an API error.
Office API family, different path shape
Excel operations live under 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 indexesYou sendWhat 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
Bothnames + indexesThe union: anything matching either list
Neither{} action objectEvery worksheet in the workbook

API body fields

ParameterRequiredTypeWhat it doesExample
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

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

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 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.

FieldTypeWhat it contains
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.

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

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.

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.

Same task on other platforms

Get Help