Convert Excel#
Important
During conversion you should not expect any Excel macros to operate as we do not support Office macros.
Available Methods#
/xls/convert/to/json#
Converts a xls
/xlsx
/csv
file to json
.
Method: POST
Endpoint: /v1/xls/convert/to/json
/xls/convert/to/html#
Converts a xls
/xlsx
/csv
file to html
.
Method: POST
Endpoint: /v1/xls/convert/to/html
/xls/convert/to/txt#
Converts a xls
/xlsx
/csv
file to txt
.
Method: POST
Endpoint: /v1/xls/convert/to/txt
/xls/convert/to/xml#
Converts a xls
/xlsx
/csv
file to xml
.
Method: POST
Endpoint: /v1/xls/convert/to/xml
/xls/convert/to/pdf#
Converts a xls
/xlsx
/csv
file to pdf
.
Method: POST
Endpoint: /v1/xls/convert/to/pdf
Attributes#
Note
Attributes are case-sensitive and should be inside JSON for POST request, for example:
{
"url": "https://example.com/file1.pdf"
}
Attribute |
Description |
Required |
---|---|---|
|
URL to the source file. 1 |
yes |
|
HTTP auth user name if required to access source |
no |
|
HTTP auth password if required to access source |
no |
|
The index of the worksheet to use. |
no |
|
Set to |
no |
|
Set |
no |
|
File name for the generated output, the input must be in string format. |
no |
|
Set the expiration time for the output link in minutes (default is |
no |
|
Use this parameter to set additional configurations for fine-tuning and extra options. Explore the Profiles section for more. |
no |
Query parameters#
No query parameters accepted.
Payload 3#
{
"url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/other/Input.xls",
"async": false,
"name": "Output"
}
Response 2#
{
"url": "https://pdf-temp-files.s3.amazonaws.com/bd58508fdbaf41cb81309e2195276305/Input.csv",
"error": false,
"status": 200,
"name": "Output.csv",
"remainingCredits": 59856
}
CURL#
curl --location --request POST 'https://api.pdf.co/v1/xls/convert/to/csv' \
--header 'x-api-key: *******************' \
--header 'Content-Type: application/json' \
--data-raw '{
"url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/other/Input.xls",
"async": false
}'
Code samples (XLS to CSV)#
var https = require("https");
var path = require("path");
var fs = require("fs");
// The authentication key (API Key).
// Get your own by registering at https://app.pdf.co
const API_KEY = "***********************************";
// Direct URL of source PDF file.
const SourceFileUrl = "https://pdfco-test-files.s3.us-west-2.amazonaws.com/other/Input.xls";
// Comma-separated list of page indices (or ranges) to process. Leave empty for all pages. Example: '0,2-5,7-'.
const Pages = "";
// PDF document password. Leave empty for unprotected documents.
const Password = "";
// Destination CSV file name
const DestinationFile = "./result.csv";
// Prepare request to `PDF To CSV` API endpoint
var queryPath = `/v1/xls/convert/to/csv`;
// JSON payload for api request
var jsonPayload = JSON.stringify({
name: path.basename(DestinationFile), password: Password, pages: Pages, url: SourceFileUrl
});
var reqOptions = {
host: "api.pdf.co",
method: "POST",
path: queryPath,
headers: {
"x-api-key": API_KEY,
"Content-Type": "application/json",
"Content-Length": Buffer.byteLength(jsonPayload, 'utf8')
}
};
// Send request
var postRequest = https.request(reqOptions, (response) => {
response.on("data", (d) => {
// Parse JSON response
var data = JSON.parse(d);
if (data.error == false) {
// Download CSV file
var file = fs.createWriteStream(DestinationFile);
https.get(data.url, (response2) => {
response2.pipe(file)
.on("close", () => {
console.log(`Generated CSV file saved as "${DestinationFile}" file.`);
});
});
}
else {
// Service reported error
console.log(data.message);
}
});
}).on("error", (e) => {
// Request error
console.log(e);
});
// Write request data
postRequest.write(jsonPayload);
postRequest.end();
import requests
import json
# Your API endpoint URL.
url = "https://api.pdf.co/v1/xls/convert/to/csv"
# Your API Key.
api_key = "Your API Key"
# The URL of the Excel file you want to convert.
input_file_url = "https://pdfco-test-files.s3.us-west-2.amazonaws.com/other/Input.xls"
headers = {
"x-api-key": api_key,
"Content-Type": "application/json"
}
data = {
"url": input_file_url,
"async": False
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
# The request was successful.
# Parse the json response.
data = response.json()
# Extract the CSV file URL from the response.
csv_url = data.get('url', '')
print("CSV file is available at: ", csv_url)
else:
# There was an error with the request.
print("Error: ", response.status_code)
Code samples (XLS to XML)#
import os
import requests # pip install requests
import json
# The authentication key (API Key).
# Get your own by registering at https://app.pdf.co
API_KEY = "***************************************"
# Base URL for PDF.co Web API requests
BASE_URL = "https://api.pdf.co/v1"
# Direct URL of source xls file.
SourceFileURL = "https://pdfco-test-files.s3.us-west-2.amazonaws.com/other/Input.xls"
def main(args = None):
convertXlsToXml(SourceFileURL)
def convertXlsToXml(sourceFileUrl):
"""Convert Xls/Xlsx to Xml using PDF.co Web API"""
# Prepare requests params as JSON
parameters = {
"url": sourceFileUrl,
"async": False
}
# Prepare URL for 'Xls to Xml' API request
url = "{}/xls/convert/to/xml".format(BASE_URL)
# Execute request and get response as JSON
response = requests.post(url, headers={ "x-api-key": API_KEY, "Content-Type": "application/json" }, data=json.dumps(parameters))
if (response.status_code == 200):
json_res = response.json()
if json_res["error"] == False:
# Get URL of result file
resultFileUrl = json_res["url"]
# Output URL of converted xml file
print(f"Result file url: {resultFileUrl}")
else:
# Show service reported error
print(json_res["message"])
else:
print(f"Request error: {response.status_code} {response.reason}")
if __name__ == '__main__':
main()
On Github#
Footnotes
- 1
Supports publicly accessible links from any source, including Google Drive, Dropbox, and PDF.co Built-In Files Storage. To upload files via the API, check out the File Upload section. Note: If you experience intermittent Access Denied or Too Many Requests errors, please try adding
cache:
to enable built-in URL caching (e.g.,cache:https://example.com/file1.pdf
). For data security, you have the option to encrypt output files and decrypt input files. Learn more about user-controlled data encryption.- 2
Main response codes as follows:
Code
Description
200
Success
400
Bad request. Typically happens because of bad input parameters, or because the input URLs can’t be reached, possibly due to access restrictions like needing a login or password.
401
Unauthorized
402
Not enough credits
445
Timeout error. To process large documents or files please use asynchronous mode (set the
async
parameter totrue
) and then check status using the /job/check endpoint. If a file contains many pages then specify a page range using thepages
parameter. The number of pages of the document can be obtained using the /pdf/info endpoint.Note
For more see the complete list of available response codes.
- 3
PDF.co Request size: API requests do not support request sizes of more than
4
megabytes in size. Please ensure that request sizes do not exceed this limit.