Interface Image

Image

Behavior common to all images in a spreadsheet.

Implementing classes

NameBrief description
OverGridImageRepresents an image over the grid in a spreadsheet.

Methods

MethodReturn typeBrief description
getHeight()IntegerReturns the actual height of this image in pixels.
getSheet()SheetReturns the sheet this image appears on.
getUrl()StringReturns a Google-hosted URL to the image.
getWidth()IntegerReturns the actual width of this image in pixels.
remove()voidDeletes this image from the spreadsheet.
setHeight(height)ImageSets the actual height of this image in pixels.
setWidth(width)ImageSets the actual width of this image in pixels.

Detailed documentation

getHeight()

Returns the actual height of this image in pixels.

// Logs the height of all images in a spreadsheet
var images = SpreadsheetApp.getActiveSpreadsheet().getImages();
for (var i = 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 following scopes:

  • 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 spreadsheet
var images = SpreadsheetApp.getActiveSpreadsheet().getImages();
for (var i = 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 following scopes:

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

getUrl()

Returns a Google-hosted URL to the image. This is not the same URL used to originally specify the image and is only guaranteed to be valid as long as the image is not deleted from the spreadsheet.

// Logs the url of all images in a spreadsheet
var images = SpreadsheetApp.getActiveSpreadsheet().getImages();
for (var i = 0; i < images.length; i++) {
  Logger.log(images[i].getUrl());
}

Return

String — The Google-hosted URL of the image.

Authorization

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

  • 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 spreadsheet
var images = SpreadsheetApp.getActiveSpreadsheet().getImages();
for (var i = 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 following scopes:

  • 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 script error.

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

Authorization

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

  • 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

Image — The image for chaining.

Authorization

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

  • 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

Image — The image for chaining.

Authorization

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

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

Send feedback about...

Apps Script
Apps Script
Need help? Visit our support page.