Class OverGridImage

  • OverGridImage represents an image placed over the grid in a spreadsheet.

  • You can assign a function to an OverGridImage and retrieve or set its alt text, anchor cell, and dimensions.

  • Methods are available to remove or replace an OverGridImage with a new image from a BlobSource or URL.

  • The deprecated getUrl() method for OverGridImage may not return a URL for newly inserted images.

OverGridImage

Represents an image over the grid in a spreadsheet.

Methods

MethodReturn typeBrief description
assignScript(functionName)OverGridImageAssigns the function with the specified function name to this image.
getAltTextDescription()StringReturns the alt text description for this image.
getAltTextTitle()StringReturns the alt text title for this image.
getAnchorCell()RangeReturns the cell where an image is anchored.
getAnchorCellXOffset()IntegerReturns the horizontal pixel offset from the anchor cell.
getAnchorCellYOffset()IntegerReturns the vertical pixel offset from the anchor cell.
getHeight()IntegerReturns the actual height of this image in pixels.
getInherentHeight()IntegerReturns the inherent height of this image in pixels.
getInherentWidth()IntegerReturns the inherent height of this image in pixels.
getScript()StringReturns the name of the function assigned to this image.
getSheet()SheetReturns the sheet this image appears on.
getWidth()IntegerReturns the actual width of this image in pixels.
remove()voidDeletes this image from the spreadsheet.
replace(blob)OverGridImageReplaces this image with the one specified by the providedBlobSource.
replace(url)OverGridImageReplaces this image with the one from the specified URL.
resetSize()OverGridImageResets this image to its inherent dimensions.
setAltTextDescription(description)OverGridImageSets the alt-text description for this image.
setAltTextTitle(title)OverGridImageSets the alt text title for this image.
setAnchorCell(cell)OverGridImageSets the cell where an image is anchored.
setAnchorCellXOffset(offset)OverGridImageSets the horizontal pixel offset from the anchor cell.
setAnchorCellYOffset(offset)OverGridImageSets the vertical pixel offset from the anchor cell.
setHeight(height)OverGridImageSets the actual height of this image in pixels.
setWidth(width)OverGridImageSets the actual width of this image in pixels.

Deprecated methods

MethodReturn typeBrief description
getUrl()StringGets the image's source URL.

Detailed documentation

assignScript(functionName)

Assigns the function with the specified function name to this image.

Parameters

NameTypeDescription
functionNameStringThe name of the function being specified. This must be a public top level function, not one ending in underscore such asprivateFunction_.

Return

OverGridImage — This image, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getAltTextDescription()

Returns the alt text description for this image.

Return

String — The alt text description.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getAltTextTitle()

Returns the alt text title for this image.

Return

String — The alt text title.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getAnchorCell()

Returns the cell where an image is anchored.

Return

Range — The anchor cell.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getAnchorCellXOffset()

Returns the horizontal pixel offset from the anchor cell.

Return

Integer — The horizontal pixel offset.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getAnchorCellYOffset()

Returns the vertical pixel offset from the anchor cell.

Return

Integer — The vertical pixel offset.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getHeight()

Returns the actual height of this image in pixels.

// Logs the height of all images in a spreadsheetconstimages=SpreadsheetApp.getActiveSpreadsheet().getImages();for(leti=0;i <images.length;i++){Logger.log(images[i].getHeight());}

Return

Integer — The height of the image in pixels.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getInherentHeight()

Returns the inherent height of this image in pixels.

Return

Integer — The inherent height in pixels.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getInherentWidth()

Returns the inherent height of this image in pixels.

Return

Integer — The inherent width in pixels.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getScript()

Returns the name of the function assigned to this image.

Return

String — The name of the function.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getSheet()

Returns the sheet this image appears on.

// Logs the parent sheet of all images in a spreadsheetconstimages=SpreadsheetApp.getActiveSpreadsheet().getImages();for(leti=0;i <images.length;i++){Logger.log(images[i].getSheet());}

Return

Sheet — The sheet the image appears on.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

getWidth()

Returns the actual width of this image in pixels.

// Logs the width of all images in a spreadsheetconstimages=SpreadsheetApp.getActiveSpreadsheet().getImages();for(leti=0;i <images.length;i++){Logger.log(images[i].getWidth());}

Return

Integer — The width of the image in pixels.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

remove()

Deletes this image from the spreadsheet. Any further operation on the image results in a scripterror.

// Deletes all images in a spreadsheetconstimages=SpreadsheetApp.getActiveSpreadsheet().getImages();for(leti=0;i <images.length;i++){images[i].remove();}

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

replace(blob)

Replaces this image with the one specified by the providedBlobSource. The maximumsupported blob size is 2MB.

Parameters

NameTypeDescription
blobBlobSourceThe new image as a Blob.

Return

OverGridImage — This image, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

replace(url)

Replaces this image with the one from the specified URL.

Parameters

NameTypeDescription
urlStringThe URL of the new image.

Return

OverGridImage — This image, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

resetSize()

Resets this image to its inherent dimensions.

Return

OverGridImage — This image, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setAltTextDescription(description)

Sets the alt-text description for this image.

Parameters

NameTypeDescription
descriptionStringThe new alt text description for the image.

Return

OverGridImage — This image, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setAltTextTitle(title)

Sets the alt text title for this image.

Parameters

NameTypeDescription
titleStringThe new alt text title for the image.

Return

OverGridImage — This image, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setAnchorCell(cell)

Sets the cell where an image is anchored.

Parameters

NameTypeDescription
cellRangeThe new anchor cell.

Return

OverGridImage — This image, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setAnchorCellXOffset(offset)

Sets the horizontal pixel offset from the anchor cell.

Parameters

NameTypeDescription
offsetIntegerThe new horizonal pixel offset.

Return

OverGridImage — This image, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setAnchorCellYOffset(offset)

Sets the vertical pixel offset from the anchor cell.

Parameters

NameTypeDescription
offsetIntegerThe new vertical pixel offset.

Return

OverGridImage — This image, for chaining.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setHeight(height)

Sets the actual height of this image in pixels.

Parameters

NameTypeDescription
heightIntegerThe desired height in pixels.

Return

OverGridImage — The image for chaining.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

setWidth(width)

Sets the actual width of this image in pixels.

Parameters

NameTypeDescription
widthIntegerThe desired width in pixels.

Return

OverGridImage — The image for chaining.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

Deprecated methods

getUrl()

Deprecated. For most newly inserted images, the source URL is unavailable.

Gets the image's source URL. Returns an empty string if the URL is unavailable. For most newlyinserted images, the source URL is unavailable regardless how the image is inserted.

Return

String — The image's source URL if available; returns an empty string otherwise.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/spreadsheets.currentonly
  • https://www.googleapis.com/auth/spreadsheets

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.