8

I'm trying to extract an in-cell-image from google sheets to later paste to a google docs. Using this method I'm getting an error and couldn't find any documentation about this.

function onClick(){
  var app = SpreadsheetApp;
  var sheet = app.getActive().getSheetByName('FILE');
  var image = sheet.getRange('D4').getValue();
  var url = image.getContentUrl()
  Logger.log(url)
}

Exception: Unexpected error while getting the method or property getContentUrl on object SpreadsheetApp.CellImage

I've also tried using this method using DocsServiceApp->

DocsServiceApp.openBySpreadsheetId(spreadsheetId)
  .getSheetByName("Sheet1")
  .getImages();

But this led to a different error:

Exception: Request failed for https://www.googleapis.com returned code 403. Truncated server response: {
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "exportSizeLimitExceeded",
    "message": "This file is too large to be expo... (use muteHttpExceptions option to examine full response)
    at gToM(SpreadsheetAppp:171:25)
    at getImages(SpreadsheetAppp:34:14)

Does anyone know how to fix one of these errors, or a different method for extracting the images from a google sheet?

4
  • 1
    Note: This was closed as a duplicate of stackoverflow.com/questions/56138090/… This is reopened as it seemed it isn't a exact duplicate. But the original duplicate might still help and maybe closed again by the community as it sees fit. Commented May 24, 2022 at 20:30
  • 1
    First, I apologize that my Google Apps Script library was not useful for your situation. From the error message of "reason": "exportSizeLimitExceeded", I'm worried that the image size might be large. So, I would like to confirm your situation. Can you provide the sample Spreadsheet for correctly replicating your current issue of "reason": "exportSizeLimitExceeded"? Commented May 24, 2022 at 23:15
  • If you share spreadsheets, do note that your email address can be accessed by the public. Commented May 25, 2022 at 0:21
  • @Tanaike Thank you very much for the library you built. It is brilliant. But yes, as you mentioned, I have many images in that spreadsheet, and they are of relatively high resolution. If there was a way to extract just specific images, and not all of them at once I'm pretty sure that would resolve it. But the library doesn't support this at present time if I understand correctly? Thanks again for helping out! Commented May 27, 2022 at 10:27

1 Answer 1

3

As of March 10, 2025, this bug has been officially fixed. Calls to getContentUrl() now function as expected.

See Google issue tracker thread linked below for details:

https://issuetracker.google.com/issues/392060830

Sign up to request clarification or add additional context in comments.

1 Comment

This appears to still be broken if the script is @OnlyCurrentDoc annotated: issuetracker.google.com/issues/392060830#comment19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.