orschiro
orschiro

Reputation: 21735

Transfer images between Google Sheets?

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

Answers (2)

Piotr Kocybik
Piotr Kocybik

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.

  1. Get Your API Key, from Google developers Console

  2. Get a File ID of a google spreadsheet with permissions set to "Anyone with the link".

  3. 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}

Upvotes: 0

Iamblichus
Iamblichus

Reputation: 19309

Answer:

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.

Feature Requests:

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:

Workarounds:

Option 1. Set image through its URL:

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).

Option 2. Copy corresponding range:

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).

Option 3. Copy the entire sheet:

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

Related Questions