Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groupdocs-cloud-gists/b9ab453349a957943be7662d796f93a4 to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/b9ab453349a957943be7662d796f93a4 to your computer and use it in GitHub Desktop.
Convert EXCEL to JSON and JSON to EXCEL in Python

You can convert EXCEL to JSON and JSON to EXCEL in Python programmatically on the cloud. In this article, we will learn how to convert EXCEL to JSON and JSON to EXCEL in Python using REST API.

The following topics shall be covered in this article:

  1. Python EXCEL to JSON and JSON to EXCEL API - Installation
  2. How to Convert EXCEL to JSON using Python
  3. How to Convert JSON to EXCEL using Python
# How to Convert EXCEL to JSON using Python
try:
# Create an instance of the API
convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(client_id, client_secret)
# Define convert settings
settings = groupdocs_conversion_cloud.ConvertSettings()
settings.storage_name = storage_name
settings.file_path = "python-testing/Sample-Spreadsheet-500000-rows.xlsx"
settings.format = "json"
settings.output_path = "python-testing"
request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
response = convert_api.convert_document(request)
print("Successfully converted EXCEL to JSON format: " + str(response))
except groupdocs_conversion_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# API initialization to download converted file
import shutil
file_api = groupdocs_conversion_cloud.FileApi.from_config(configuration)
# Create download json file request
request = groupdocs_conversion_cloud.DownloadFileRequest("python-testing\\Sample-Spreadsheet-500000-rows.json", storage_name)
# Download converted file
response = file_api.download_file(request)
# Move the downloaded json file to your local directory
shutil.move(response, "H:\\groupdocs-cloud-data\\")
# Upload Excel xlsx file to cloud storage
# Create an instance of the File API
file_api = groupdocs_conversion_cloud.FileApi.from_config(configuration)
# Call upload file request
request = groupdocs_conversion_cloud.UploadFileRequest("python-testing\Sample-Spreadsheet-500000-rows.xlsx", "H:\\groupdocs-cloud-data\\Sample-Spreadsheet-500000-rows.xlsx", storage_name)
# Upload xlsx file to the cloud
response = file_api.upload_file(request)
print(response.uploaded)
# How to Convert JSON to EXCEL using Python
try:
# Create an instance of the API
convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(client_id, client_secret)
# Define convert settings
settings = groupdocs_conversion_cloud.ConvertSettings()
settings.storage_name = storage_name
settings.file_path = "python-testing/sample-json-file.json"
settings.format = "xlsx"
settings.output_path = "python-testing"
request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
response = convert_api.convert_document(request)
print("Successfully converted json to xlsx file: " + str(response))
except groupdocs_conversion_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# Import Python SDK in your python application from http://api.groupdocs.cloud
import groupdocs_conversion_cloud
# Get client_id and client_secret from https://dashboard.groupdocs.cloud after free registration.
client_id = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
client_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Get File API configurations
configuration = groupdocs_conversion_cloud.Configuration(client_id, client_secret)
configuration.api_base_url = "https://api.groupdocs.cloud"
storage_name = "InternalStorage"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment