1

I need to extract an image from a Google Sheets spreadsheet. It is not connected to a cell, and does not have an URL--it's just an inserted image:

How can I extract it using Python?

Thank you very much for an answer.

here is a part of a code:

import gspread 
from oauth2client.service_account import ServiceAccountCredentials 
import urllib 
import numpy as numpy 
scopes = ['spreadsheets.google.com/feeds'] 
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json',scopes) 
client = gspread.authorize(creds) 
spreadsheet = client.open_by_url("docs.google.com/spreadsheets/d/…) 
worksheet = spreadsheet.worksheet("Ark1") 
list_of_lists = worksheet.range('A1:Q31') 
print('{}\n'.format(list_of_lists))
tehhowch
  • 9,645
  • 4
  • 24
  • 42
  • Take a picture with your smartphone; unless you paste a minimal example you work on this question is considered asking for manual and belongs to a forum. – ZF007 Mar 11 '19 at 13:39
  • Welcome to SO. Please finish the tour and you will understand [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) and modify question accordingly to minimal working example. Without posting your code you risk removal of your question. With your stated trail and error code... people are more willing to help you so we both can learn. Enjoy SO ;-) – ZF007 Mar 11 '19 at 13:41
  • Please, show what you've been trying so far - your code snippets. – kosist Mar 11 '19 at 13:54
  • 1
    `client_secret.json` is typically used with Google OAuth 2.0 User Credentials. You are trying to load that Json file into a Google Service Account. This will not work for Client Secrets. Unless you have G Suite Domain Wide Delegation enabled, service account credentials will not work either. If you have enabled delegation, your code will not work as you are not delegating identities. You do want to use User Credentials, however your code is not written correctly. Read this link to understand what you need to understand: https://developers.google.com/identity/protocols/OAuth2 – John Hanley Mar 12 '19 at 07:38
  • it does not answer my question. Is it possible to extract Image from a Worksheet if it is not inserted into a cell and does not have an URL, it just is in a worksheet there? – Ievgen Perederieiev Mar 13 '19 at 08:09
  • You can view all possible things the API can access by reviewing the Google Sheets REST API documentation (specifically, resource representations for `Spreadsheet` and `Sheet`). You are expected to have read the official API docs. If the API has no "images on the sheet" representation, the answer is no. If the API does, your next question is "Does `gspread` implement it?" If `gspread` does, voila, you have your answer. If it does not, then you must alter your approach, and perform some code experiments, Ask specific questions about those code experiments that you cannot make work. – tehhowch Mar 14 '19 at 14:52
  • tehhowch , Thank you) Unfortunately `gspread` does not have "images on the sheet" representation(( and the only way to extract image is when it is inserted into a cell with formula `=IMAGE('Image_URL')`. – Ievgen Perederieiev Mar 15 '19 at 12:47

0 Answers0