Skip to content

Instantly share code, notes, and snippets.

@groupdocs-cloud-gists
Last active January 14, 2022 09:43
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/9101dc0a1e8f5af9649d2c18a703139d to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/9101dc0a1e8f5af9649d2c18a703139d to your computer and use it in GitHub Desktop.
Convert Excel to CSV using REST API in Python.

Learn how to convert Excel files to CSV using a REST API in Python: https://blog.groupdocs.cloud/2022/01/12/convert-excel-to-csv-using-rest-api-in-python/

The following topics shall be covered in this article:

  1. Excel to CSV Conversion REST API and Python SDK
  2. Convert Excel to CSV using a REST API in Python
  3. Convert Excel to CSV and Download File Directly
  4. Excel to CSV Conversion without using Cloud Storage
  5. Convert CSV to Excel using a REST API in Python
# The following code example demonstrates how to add Client id and secret in the code.
client_id = "659fe7da-715b-4744-a0f7-cf469a392b73"
client_secret = "b377c36cfa28fa69960ebac6b6e36421"
configuration = groupdocs_conversion_cloud.Configuration(client_id, client_secret)
configuration.api_base_url = "https://api.groupdocs.cloud"
my_storage = ""
# This code example demonstrates how to convert Excel to CSV.
# Create necessary API instance
convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(client_id, client_secret)
# Prepare convert settings
settings = groupdocs_conversion_cloud.ConvertSettings()
settings.file_path = "Sample.xlsx" # Input file
settings.format = "csv" # Output format
settings.output_path = "output" # Folder path to save converted file
# Convert document request
request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
# Convert document
result = convert_api.convert_document(request)
# Done
print("Document converted: " + result[0].path)
# This code example demonstrates how to convert Excel to CSV and download converted file directly.
# Create necessary API instances
convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(client_id, client_secret)
# Prepare convert settings
settings = groupdocs_conversion_cloud.ConvertSettings()
settings.file_path = "sample.xlsx"
settings.format = "csv"
settings.output_path = None # leave OutputPath will result the output as document IOStream
# Prepare request
request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
# Convert and download
response = convert_api.convert_document_download(request)
# Move downloaded file to your working directory
shutil.move(response, "C:\\Files\\Conversion\\")
# This code example demonstrates how to convert CSV to Excel.
# Create necessary API instances
convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(client_id, client_secret)
# Prepare request
request = groupdocs_conversion_cloud.ConvertDocumentDirectRequest("xlsx", "C:\\Files\\Conversion\\sample.csv")
# Convert
result = convert_api.convert_document_direct(request)
# Move downloaded file to your working directory
shutil.move(result, "C:\\Files\\Conversion\\")
# This code example demonstrates how to convert Excel to CSV and without using cloud storage.
# Create necessary API instances
convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(client_id, client_secret)
# Prepare request
request = groupdocs_conversion_cloud.ConvertDocumentDirectRequest("csv", "C:\\Files\\Conversion\\sample.xlsx")
# Convert
result = convert_api.convert_document_direct(request)
# Move downloaded file to your working directory
shutil.move(result, "C:\\Files\\Conversion\\")
# This code example demonstartes how to download CSV from the cloud.
# API initialization
file_api = groupdocs_conversion_cloud.FileApi.from_config(configuration)
# Downlaod file request
request = groupdocs_conversion_cloud.DownloadFileRequest("output/Sample.csv", my_storage)
# download file
response = file_api.download_file(request)
# Move downloaded file to your working directory
shutil.move(response, "C:\\Files\\Conversion\\")
# This code example demonstrates how to upload an XLSX file to the cloud.
# Create an instance of the API
file_api = groupdocs_conversion_cloud.FileApi.from_config(configuration)
# Upload file request
request = groupdocs_conversion_cloud.UploadFileRequest("Sample.xlsx", "C:\\Files\\Conversion\\Sample.xlsx", my_storage)
# Upload sample file
response = file_api.upload_file(request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment