Class Drawing

  • TheDrawing class represents a drawing object placed on a spreadsheet sheet.

  • You can retrieve information about a drawing's position, dimensions (height and width), attached macro, parent sheet, and z-index.

  • Drawings can be removed from the spreadsheet using theremove() method.

  • You can set the height, width, position, and z-index of a drawing using dedicated methods.

  • Macros can be assigned to drawings using thesetOnAction() method.

Drawing

Represents a drawing over a sheet in a spreadsheet.

Methods

MethodReturn typeBrief description
getContainerInfo()ContainerInfoGets information about where the drawing is positioned in the sheet.
getHeight()IntegerReturns the actual height of this drawing in pixels.
getOnAction()String|nullReturns the name of the macro attached to this drawing.
getSheet()SheetReturns the sheet this drawing appears on.
getWidth()IntegerReturns the actual width of this drawing in pixels.
getZIndex()NumberReturns the z-index of this drawing.
remove()voidDeletes this drawing from the spreadsheet.
setHeight(height)DrawingSets the actual height of this drawing in pixels.
setOnAction(macroName)DrawingAssigns a macro function to this drawing.
setPosition(anchorRowPos, anchorColPos, offsetX, offsetY)DrawingSets the position where the drawing appears on the sheet.
setWidth(width)DrawingSets the actual width of this drawing in pixels.
setZIndex(zIndex)DrawingSets the z-index of this drawing.

Detailed documentation

getContainerInfo()

Gets information about where the drawing is positioned in the sheet.

Return

ContainerInfo — An object containing the drawing's container position.

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 drawing in pixels.

// Logs the height of all drawings in a sheetconstdrawings=SpreadsheetApp.getActiveSheet().getDrawings();for(leti=0;i <drawings.length;i++){Logger.log(drawings[i].getHeight());}

Return

Integer — The height of the drawing 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

getOnAction()

Returns the name of the macro attached to this drawing.

// Logs the macro name of all drawings on the active sheet.constdrawings=SpreadsheetApp.getActiveSheet().getDrawings();for(leti=0;i <drawings.length;i++){Logger.log(drawings[i].getOnAction());}

Return

String|null — The macro name attached to this drawing.

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 drawing appears on.

// Logs the parent sheet of all drawings on the active sheet.constdrawings=SpreadsheetApp.getActiveSheet().getDrawings();for(leti=0;i <drawings.length;i++){Logger.log(drawings[i].getSheet());}

Return

Sheet — The sheet the drawing 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 drawing in pixels.

// Logs the width of all drawings in a sheetconstdrawings=SpreadsheetApp.getActiveSheet().getDrawings();for(leti=0;i <drawings.length;i++){Logger.log(drawings[i].getWidth());}

Return

Integer — The width of the drawing 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

getZIndex()

Returns the z-index of this drawing.

// Logs the z-index of all drawings on the active sheet.constdrawings=SpreadsheetApp.getActiveSheet().getDrawings();for(leti=0;i <drawings.length;i++){Logger.log(drawings[i].getZIndex());}

Return

Number — Z-Index of this drawing.

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 drawing from the spreadsheet. Any further operation on the drawing results in ascript error.

// Deletes all drawings from the active sheet.constdrawings=SpreadsheetApp.getActiveSheet().getDrawings();for(leti=0;i <drawings.length;i++){drawings[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

setHeight(height)

Sets the actual height of this drawing in pixels.

Parameters

NameTypeDescription
heightIntegerThe desired height in pixels.

Return

Drawing — This drawing, 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

setOnAction(macroName)

Assigns a macro function to this drawing.

Parameters

NameTypeDescription
macroNameStringName of the macro function.

Return

Drawing — This drawing, for chaining.


setPosition(anchorRowPos, anchorColPos, offsetX, offsetY)

Sets the position where the drawing appears on the sheet. The anchor row and column positionindices are 1-indexed.

Parameters

NameTypeDescription
anchorRowPosIntegerThe drawing's top side is anchored in this row.
anchorColPosIntegerThe drawing's top side is anchored in this col.
offsetXIntegerThe horizontal offset from the cell corner in pixels.
offsetYIntegerThe vertical offset from the cell corner in pixels.

Return

Drawing — This drawing, 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 drawing in pixels.

Parameters

NameTypeDescription
widthIntegerThe desired width in pixels.

Return

Drawing — This drawing, 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

setZIndex(zIndex)

Sets the z-index of this drawing.

Parameters

NameTypeDescription
zIndexNumberZ-Index of this drawing.

Return

Drawing — This drawing, for chaining.

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.