Reputation: 21735
Is there a way, using the Google Sheets API, to transfer images from one Google Sheet to another that have been added using Insert > Image
?
I had a look at the possibilities of Importrange but there doesn't seem to be a way to transfer images using that.
Upvotes: 0
Views: 7252
Reputation: 121
You can download a zip file with the sheet in html format using Google API. It will contain all images, no matter how were they added.
Get Your API Key, from Google developers Console
Get a File ID of a google spreadsheet with permissions set to "Anyone with the link".
Now you're ready to call the api (with curl or browser window):
https://www.googleapis.com/drive/v3/files/{FILE_ID}/export?mimeType=application%2Fzip&key={YOUR API KEY}
Remember to fill the above with Your FILE_ID and your API_KEY from google.
This works only for files with "anyone with link" permissions, otherwise you'll have to authenticate first. (see my answer here: How to send google-sheet data in an email keeping the formatting( colors) intact from python?)
Upvotes: 0
Reputation: 19309
Unfortunately, there is currently no way to retrieve images added through Insert > Image
via Sheets API, so all you have are several roundabout ways, which will only be appropriate in certain circumstances.
There are several feature requests in Issue Tracker regarding image handling in Sheets API, I'd suggest you to star these in order to keep track of them and to help prioritize its implementation:
If a URL of the image is available and you want to write the image to a specific cell (not over cells
), you could just add the formula =IMAGE(your-image-url)
to the desired cell via spreadsheets.values.update.
Or, if you're open to using Apps Script, you could use insertImage(url, column, row).
If the image was added via Insert > Images > Image in cell
and the destination sheet is on the same spreadsheet as the source sheet, you could make a CopyPasteRequest or a CutPasteRequest to copy or move the range containing the image to the destination sheet (see spreadsheets.batchUpdate).
If the image was added via Insert > Images > Image over cells
, or if the destination sheet is not on the same spreadsheet as the source sheet, your only option would be to copy the entire sheet via spreadsheets.sheets.copyTo.
Upvotes: 2