Download Spreadsheet Using Sheets API in Python

Many of us find it difficult or do not have a right technique to download spreadsheet using sheets API in Python.

This article has been created for users who would like to download spreadsheet for reporting and for any other purpose. Users can now easily automate the reports using the article.

To know an end to end process on how you can download spreadsheet in any format.

This component is useful for downloading spreadsheet using sheets API in python. This is an end to end process where you can download spreadsheet in any format. Kindly refer to the steps below.

Download ini file and python file from current repository.

  1. Run the below command

  2. Now go to the below link;

  3. If projectis already created. Select project else create new project

  4. Click on ENABLE API

  5. Now search for Google Sheets API, click on Google Sheets API.

  6. Check Google Sheets API & Drive API are ENABLE or DISABLE. If it is already ENABLED then screen would be appear as below.

  7. Then Go to credentials. (On top left)

  8. At the top of the page, select the OAuth consent screen tab. Select an Email address, enter a Product name if not already set, and click the Save button.

  9. Select the Credentials tab, click the Create credentials button and select OAuth client ID.

  10. Select the application type as Other, enter the name , and click the Create button.

  11. Click OK to dismiss the resulting dialog.

  12. Click on the download icon (Download JSON) on the right side of the client id.

  13. Move this file to your working directory and rename it as client_secret.json.

  14. Give access permission to the folder in which you want to download the file using below command

  15. Fill the credential in ini file and, run the below command.

  16. python 'fileDownloadfromGdrive.ini'

  17. Ini file parameter description is below

    (i) clientsecretkeypath = your dir path/client_secret.json

    (ii) spreadsheetid = your spreadsheet id

    (iii) filename = file name you want to save

    (iv) filepath = file path where you want to save

    (v) mimetype = application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

  18. Mime list is below:

    (i) MS Excel = application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

    (ii) Open Office sheet = application/x-vnd.oasis.opendocument.spreadsheet

    (iii) PDF = application/pdf

    (iv) CSV (first sheet only) = text/csv

    (v) TSV (first sheet only) = text/tab-separated-values

    (vi) HTML (zipped) = application/zip

    Leave a comment