Spreadsheet Script by Google
Spreadsheet Script by Google
Access and modify Google Sheets les. Common operations are adding new sheets and adding collaborators.
Methods
addDeveloperMetadata(key)
(#addDeveloperMetadata(String)) Spreadsheet (#) Adds developer metadata with the speci ed key to the top-level
spreadsheet.
addDeveloperMetadata(key, visibility) Spreadsheet (#) Adds developer metadata with the speci ed key and visibility to the
(#addDeveloperMetadata(String,DeveloperMetadataVisibility)) spreadsheet.
addDeveloperMetadata(key, value)
(#addDeveloperMetadata(String,String)) Spreadsheet (#) Adds developer metadata with the speci ed key and value to the
spreadsheet.
addDeveloperMetadata(key, value, visibility) Spreadsheet (#) Adds developer metadata with the speci ed key, value, and visibility to the
(#addDeveloperMetadata(String,String,DeveloperMetadataVisibility)) spreadsheet.
addEditor(emailAddress)
(#addEditor(String)) Spreadsheet (#) Adds the given user to the list of editors for the Spreadsheet (#).
addEditor(user)
(#addEditor(User)) Spreadsheet (#) Adds the given user to the list of editors for the Spreadsheet (#).
addEditors(emailAddresses)
(#addEditors(String)) Spreadsheet (#) Adds the given array of users to the list of editors for the Spreadsheet (#).
addMenu(name, subMenus)
(#addMenu(String,Object)) void Creates a new menu in the Spreadsheet UI.
addViewer(emailAddress)
(#addViewer(String)) Spreadsheet (#) Adds the given user to the list of viewers for the Spreadsheet (#).
addViewer(user)
(#addViewer(User)) Spreadsheet (#) Adds the given user to the list of viewers for the Spreadsheet (#).
addViewers(emailAddresses)
(#addViewers(String)) Spreadsheet (#) Adds the given array of users to the list of viewers for the Spreadsheet (#)
.
appendRow(rowContents)
(#appendRow(Object)) Sheet Appends a row to the spreadsheet.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
autoResizeColumn(columnPosition)
(#autoResizeColumn(Integer)) Sheet Sets the width of the given column to t its contents.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
copy(name)
(#copy(String)) Spreadsheet (#) Copies the spreadsheet and returns the new one.
createDeveloperMetadataFinder()
(#createDeveloperMetadataFinder()) DeveloperMetadataFinder Returns a DeveloperMetadataFinderApi for nding developer metadata
(https://developers.google.com/apps- within the scope of this spreadsheet.
script/reference/spreadsheet/developer-metadata- nder.html)
createTextFinder(findText)
(#createTextFinder(String)) TextFinder Creates a text nder for the spreadsheet, which can be used to nd and
(https://developers.google.com/apps- replace text within the spreadsheet.
script/reference/spreadsheet/text- nder.html)
deleteActiveSheet()
(#deleteActiveSheet()) Sheet Deletes the currently active sheet.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
deleteColumn(columnPosition)
(#deleteColumn(Integer)) Sheet Deletes the column at the given column position.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
deleteColumns(columnPosition, howMany)
(#deleteColumns(Integer,Integer)) void Deletes a number of columns starting at the given column position.
deleteRow(rowPosition)
(#deleteRow(Integer)) Sheet Deletes the row at the given row position.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
deleteRows(rowPosition, howMany)
(#deleteRows(Integer,Integer)) void Deletes a number of rows starting at the given row position.
deleteSheet(sheet)
(#deleteSheet(Sheet)) void Deletes the speci ed sheet.
duplicateActiveSheet()
(#duplicateActiveSheet()) Sheet Duplicates the active sheet and makes it the active sheet.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
getActiveCell()
(#getActiveCell()) Range Returns the active cell in this sheet.
(https://developers.google.com/apps-
script/reference/spreadsheet/range.html)
getActiveRange()
(#getActiveRange()) Range Returns the selected range in the active sheet, or null if there is no active
(https://developers.google.com/apps- range.
script/reference/spreadsheet/range.html)
getActiveRangeList()
(#getActiveRangeList()) RangeList Returns the list of active ranges in the active sheet or null if there are no
(https://developers.google.com/apps- active ranges.
script/reference/spreadsheet/range-list.html)
getActiveSheet()
(#getActiveSheet()) Sheet Gets the active sheet in a spreadsheet.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
getAs(contentType)
(#getAs(String)) Blob Return the data inside this object as a blob converted to the speci ed
(https://developers.google.com/apps-script/reference/base/blob.html) content type.
getBandings()
(#getBandings()) Banding[] Returns all the bandings in this spreadsheet.
(https://developers.google.com/apps-
script/reference/spreadsheet/banding.html)
getBlob()
(#getBlob()) Blob Return the data inside this object as a blob.
(https://developers.google.com/apps-script/reference/base/blob.html)
getColumnWidth(columnPosition)
(#getColumnWidth(Integer)) Integer Gets the width in pixels of the given column.
getCurrentCell()
(#getCurrentCell()) Range Returns the current cell in the active sheet or null if there is no current cell.
(https://developers.google.com/apps-
script/reference/spreadsheet/range.html)
getDataRange()
(#getDataRange()) Range Returns a Range
(https://developers.google.com/apps- (https://developers.google.com/apps-
script/reference/spreadsheet/range.html) script/reference/spreadsheet/range.html)
corresponding to the dimensions in which data is present.
getDataSourceTables()
(#getDataSourceTables()) DataSourceTable[] Gets all the data source tables.
(https://developers.google.com/apps-
script/reference/spreadsheet/data-source-table.html)
getDeveloperMetadata()
(#getDeveloperMetadata()) DeveloperMetadata[] Get the developer metadata associated with the top-level spreadsheet.
(https://developers.google.com/apps-
script/reference/spreadsheet/developer-metadata.html)
getEditors()
(#getEditors()) User[] Gets the list of editors for this Spreadsheet (#).
(https://developers.google.com/apps-script/reference/base/user.html)
getFormUrl()
(#getFormUrl()) String Returns the URL for the form that sends its responses to this spreadsheet,
or null if this spreadsheet has no associated form.
getFrozenColumns()
(#getFrozenColumns()) Integer Returns the number of frozen columns.
getFrozenRows()
(#getFrozenRows()) Integer Returns the number of frozen rows.
getId()
(#getId()) String Gets a unique identi er for this spreadsheet.
getImages()
(#getImages()) OverGridImage[] Returns all over-the-grid images on the sheet.
(https://developers.google.com/apps-
script/reference/spreadsheet/over-grid-image.html)
getIterativeCalculationConvergenceThreshold()
(#getIterativeCalculationConvergenceThreshold())Number Returns the threshold value used during iterative calculation.
getLastColumn()
(#getLastColumn()) Integer Returns the position of the last column that has content.
getLastRow()
(#getLastRow()) Integer Returns the position of the last row that has content.
getMaxIterativeCalculationCycles()
(#getMaxIterativeCalculationCycles()) Integer Returns the maximum number of iterations to use during iterative
calculation.
getName()
(#getName()) String Gets the name of the document.
getNamedRanges()
(#getNamedRanges()) NamedRange[] Gets all the named ranges in this spreadsheet.
(https://developers.google.com/apps-
script/reference/spreadsheet/named-range.html)
getNumSheets()
(#getNumSheets()) Integer Returns the number of sheets in this spreadsheet.
getOwner()
(#getOwner()) User Returns the owner of the document, or null for a document in a shared
(https://developers.google.com/apps-script/reference/base/user.html) drive.
getProtections(type)
(#getProtections(ProtectionType)) Protection[] Gets an array of objects representing all protected ranges or sheets in the
(https://developers.google.com/apps- spreadsheet.
script/reference/spreadsheet/protection.html)
getRange(a1Notation)
(#getRange(String)) Range Returns the range as speci ed in A1 notation or R1C1 notation.
(https://developers.google.com/apps-
script/reference/spreadsheet/range.html)
getRangeByName(name)
(#getRangeByName(String)) Range Returns a named range, or null if no range with the given name is found.
(https://developers.google.com/apps-
script/reference/spreadsheet/range.html)
getRangeList(a1Notations)
(#getRangeList(String)) RangeList Returns the RangeList
(https://developers.google.com/apps- (https://developers.google.com/apps-script/reference/spreadsheet/range-
script/reference/spreadsheet/range-list.html) list.html)
collection representing the ranges in the same sheet speci ed by a non-
empty list of A1 notations or R1C1 notations.
getRecalculationInterval()
(#getRecalculationInterval()) RecalculationInterval Returns the calculation interval for this spreadsheet.
(https://developers.google.com/apps-
script/reference/spreadsheet/recalculation-interval.html)
getRowHeight(rowPosition)
(#getRowHeight(Integer)) Integer Gets the height in pixels of the given row.
getSelection()
(#getSelection()) Selection Returns the current Selection
(https://developers.google.com/apps- (https://developers.google.com/apps-
script/reference/spreadsheet/selection.html) script/reference/spreadsheet/selection.html)
in the spreadsheet.
getSheetByName(name)
(#getSheetByName(String)) Sheet Returns a sheet with the given name.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
getSheetId()
(#getSheetId()) Integer Returns the ID of the sheet represented by this object.
getSheetName()
(#getSheetName()) String Returns the sheet name.
getSheetValues(startRow, startColumn, numRows, numColumns) Object[][] Returns the rectangular grid of values for this range starting at the given
(#getSheetValues(Integer,Integer,Integer,Integer)) coordinates.
getSheets()
(#getSheets()) Sheet[] Gets all the sheets in this spreadsheet.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
getSpreadsheetLocale()
(#getSpreadsheetLocale()) String Gets the spreadsheet locale.
getSpreadsheetTimeZone()
(#getSpreadsheetTimeZone()) String Gets the time zone for the spreadsheet.
getUrl()
(#getUrl()) String Returns the URL for the given spreadsheet.
getViewers()
(#getViewers()) User[] Gets the list of viewers and commenters for this Spreadsheet (#).
(https://developers.google.com/apps-script/reference/base/user.html)
hideColumn(column)
(#hideColumn(Range)) void Hides the columns in the given range.
hideRow(row)
(#hideRow(Range)) void Hides the rows in the given range.
insertColumnAfter(afterPosition)
(#insertColumnAfter(Integer)) Sheet Inserts a column after the given column position.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
insertColumnBefore(beforePosition)
(#insertColumnBefore(Integer)) Sheet Inserts a column before the given column position.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
insertColumnsAfter(afterPosition, howMany)
(#insertColumnsAfter(Integer,Integer)) Sheet Inserts a number of columns after the given column position.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
insertColumnsBefore(beforePosition, howMany)
(#insertColumnsBefore(Integer,Integer)) Sheet Inserts a number of columns before the given column position.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
insertImage(blobSource, column, row, offsetX, offsetY) OverGridImage Inserts a Spreadsheet (#) as an image in the document at a given row
(#insertImage(BlobSource,Integer,Integer,Integer,Integer)) (https://developers.google.com/apps- and column, with a pixel offset.
script/reference/spreadsheet/over-grid-image.html)
insertImage(url, column, row, offsetX, offsetY) OverGridImage Inserts an image in the document at a given row and column, with a pixel
(#insertImage(String,Integer,Integer,Integer,Integer)) (https://developers.google.com/apps- offset.
script/reference/spreadsheet/over-grid-image.html)
insertRowAfter(afterPosition)
(#insertRowAfter(Integer)) Sheet Inserts a row after the given row position.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
insertRowBefore(beforePosition)
(#insertRowBefore(Integer)) Sheet Inserts a row before the given row position.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
insertRowsAfter(afterPosition, howMany)
(#insertRowsAfter(Integer,Integer)) Sheet Inserts a number of rows after the given row position.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
insertRowsBefore(beforePosition, howMany)
(#insertRowsBefore(Integer,Integer)) Sheet Inserts a number of rows before the given row position.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
insertSheet()
(#insertSheet()) Sheet Inserts a new sheet into the spreadsheet, using a default sheet name.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
insertSheet(sheetIndex)
(#insertSheet(Integer)) Sheet Inserts a new sheet into the spreadsheet at the given index.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
insertSheet(sheetIndex, options)
(#insertSheet(Integer,Object)) Sheet Inserts a new sheet into the spreadsheet at the given index and uses
(https://developers.google.com/apps- optional advanced arguments.
script/reference/spreadsheet/sheet.html)
insertSheet(options)
(#insertSheet(Object)) Sheet Inserts a new sheet into the spreadsheet, using a default sheet name and
(https://developers.google.com/apps- optional advanced arguments.
script/reference/spreadsheet/sheet.html)
insertSheet(sheetName)
(#insertSheet(String)) Sheet Inserts a new sheet into the spreadsheet with the given name.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
insertSheet(sheetName, sheetIndex)
(#insertSheet(String,Integer)) Sheet Inserts a new sheet into the spreadsheet with the given name at the given
index.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
insertSheet(sheetName, options)
(#insertSheet(String,Object)) Sheet Inserts a new sheet into the spreadsheet with the given name and uses
(https://developers.google.com/apps- optional advanced arguments.
script/reference/spreadsheet/sheet.html)
insertSheetWithDataSourceTable(spec)
(#insertSheetWithDataSourceTable(DataSourceSpec)) Sheet Inserts a new sheet in the spreadsheet, creates a DataSourceTable
(https://developers.google.com/apps- (https://developers.google.com/apps-script/reference/spreadsheet/data-
script/reference/spreadsheet/sheet.html) source-table.html)
spanning the entire sheet with the given data source speci cation, and
starts data execution.
isColumnHiddenByUser(columnPosition)
(#isColumnHiddenByUser(Integer)) Boolean Returns whether the given column is hidden by the user.
isIterativeCalculationEnabled()
(#isIterativeCalculationEnabled()) Boolean Returns whether iterative calculation is enabled in this spreadsheet.
isRowHiddenByFilter(rowPosition)
(#isRowHiddenByFilter(Integer)) Boolean Returns whether the given row is hidden by a lter (not a lter view).
isRowHiddenByUser(rowPosition)
(#isRowHiddenByUser(Integer)) Boolean Returns whether the given row is hidden by the user.
moveActiveSheet(pos)
(#moveActiveSheet(Integer)) void Moves the active sheet to the given position in the list of sheets.
moveChartToObjectSheet(chart)
(#moveChartToObjectSheet(EmbeddedChart)) Sheet Creates a new SheetType.OBJECT
(https://developers.google.com/apps- (https://developers.google.com/apps-script/reference/spreadsheet/sheet-
script/reference/spreadsheet/sheet.html) type.html#OBJECT)
sheet and moves the provided chart to it.
removeEditor(emailAddress)
(#removeEditor(String)) Spreadsheet (#) Removes the given user from the list of editors for the Spreadsheet (#).
removeEditor(user)
(#removeEditor(User)) Spreadsheet (#) Removes the given user from the list of editors for the Spreadsheet (#).
removeMenu(name)
(#removeMenu(String)) void Removes a menu that was added by addMenu(name, subMenus)
(#addMenu(String,Object)).
removeNamedRange(name)
(#removeNamedRange(String)) void Deletes a named range with the given name.
removeViewer(emailAddress)
(#removeViewer(String)) Spreadsheet (#) Removes the given user from the list of viewers and commenters for the
Spreadsheet (#).
removeViewer(user)
(#removeViewer(User)) Spreadsheet (#) Removes the given user from the list of viewers and commenters for the
Spreadsheet (#).
rename(newName)
(#rename(String)) void Renames the document.
renameActiveSheet(newName)
(#renameActiveSheet(String)) void Renames the current active sheet to the given new name.
setActiveRange(range)
(#setActiveRange(Range)) Range Sets the speci ed range as the active range (#getActiveRange()) in the
(https://developers.google.com/apps- active sheet, with the top left cell in the range as the current cell
script/reference/spreadsheet/range.html) (#getCurrentCell()).
setActiveRangeList(rangeList)
(#setActiveRangeList(RangeList)) RangeList Sets the speci ed list of ranges as the active ranges
(https://developers.google.com/apps- (#getActiveRangeList()) in the active sheet.
script/reference/spreadsheet/range-list.html)
setActiveSelection(range)
(#setActiveSelection(Range)) Range Sets the active selection region for this sheet.
(https://developers.google.com/apps-
script/reference/spreadsheet/range.html)
setActiveSelection(a1Notation)
(#setActiveSelection(String)) Range Sets the active selection, as speci ed in A1 notation or R1C1 notation.
(https://developers.google.com/apps-
script/reference/spreadsheet/range.html)
setActiveSheet(sheet)
(#setActiveSheet(Sheet)) Sheet Sets the given sheet to be the active sheet in the spreadsheet.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
setActiveSheet(sheet, restoreSelection)
(#setActiveSheet(Sheet,Boolean)) Sheet Sets the given sheet to be the active sheet in the spreadsheet, with an
(https://developers.google.com/apps- option to restore the most recent selection within that sheet.
script/reference/spreadsheet/sheet.html)
setColumnWidth(columnPosition, width)
(#setColumnWidth(Integer,Integer)) Sheet Sets the width of the given column in pixels.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
setCurrentCell(cell)
(#setCurrentCell(Range)) Range Sets the speci ed cell as the current cell (#getCurrentCell()).
(https://developers.google.com/apps-
script/reference/spreadsheet/range.html)
setFrozenColumns(columns)
(#setFrozenColumns(Integer)) void Freezes the given number of columns.
setFrozenRows(rows)
(#setFrozenRows(Integer)) void Freezes the given number of rows.
setIterativeCalculationConvergenceThreshold(minThreshold) Spreadsheet (#) Sets the minimum threshold value for iterative calculation.
(#setIterativeCalculationConvergenceThreshold(Number))
setIterativeCalculationEnabled(isEnabled)
(#setIterativeCalculationEnabled(Boolean)) Spreadsheet (#) Sets whether iterative calculation is enabled in this spreadsheet.
setMaxIterativeCalculationCycles(maxIterations)
(#setMaxIterativeCalculationCycles(Integer)) Spreadsheet (#) Sets the maximum number of calculation iterations that should be
performed during iterative calculation.
setNamedRange(name, range)
(#setNamedRange(String,Range)) void Names a range.
setRowHeight(rowPosition, height)
(#setRowHeight(Integer,Integer)) Sheet Sets the row height of the given row in pixels.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
setSpreadsheetLocale(locale)
(#setSpreadsheetLocale(String)) void Sets the spreadsheet locale.
setSpreadsheetTimeZone(timezone)
(#setSpreadsheetTimeZone(String)) void Sets the time zone for the spreadsheet.
show(userInterface)
(#show(Object)) void Displays a custom user interface component in a dialog centered in the
user's browser's viewport.
sort(columnPosition)
(#sort(Integer)) Sheet Sorts a sheet by column, ascending.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
sort(columnPosition, ascending)
(#sort(Integer,Boolean)) Sheet Sorts a sheet by column.
(https://developers.google.com/apps-
script/reference/spreadsheet/sheet.html)
toast(msg)
(#toast(String)) void Shows a popup window in the lower right corner of the spreadsheet with the
given message.
toast(msg, title)
(#toast(String,String)) void Shows a popup window in the lower right corner of the spreadsheet with the
given message and title.
unhideColumn(column)
(#unhideColumn(Range)) void Unhides the column in the given range.
unhideRow(row)
(#unhideRow(Range)) void Unhides the row in the given range.
updateMenu(name, subMenus)
(#updateMenu(String,Object)) void Updates a menu that was added by addMenu(name, subMenus)
(#addMenu(String,Object)).
Deprecated methods
getSheetProtection()
(#getSheetProtection()) PageProtection Returns a PageProtection
(https://developers.google.com/apps- (https://developers.google.com/apps-script/reference/spreadsheet/page-protection.html) instance describing
script/reference/spreadsheet/page-protection.html) the permissions for the current sheet.
isAnonymousView()
(#isAnonymousView()) Boolean Indicates whether the document allows anonymous viewing.
isAnonymousWrite()
(#isAnonymousWrite()) Boolean Indicates whether the document allows edits from anonymous users.
setAnonymousAccess(anonymousReadAllowed, void Sets the document's policy on anonymous reading and writing.
anonymousWriteAllowed)
(#setAnonymousAccess(Boolean,Boolean))
Detailed documentation
addDeveloperMetadata(key)
Adds developer metadata with the speci ed key to the top-level spreadsheet.
Parameters
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
addDeveloperMetadata(key, visibility)
Adds developer metadata with the speci ed key and visibility to the spreadsheet.
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
addDeveloperMetadata(key, value)
Adds developer metadata with the speci ed key and value to the spreadsheet.
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
Adds developer metadata with the speci ed key, value, and visibility to the spreadsheet.
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
addEditor(emailAddress)
Adds the given user to the list of editors for the Spreadsheet (#). If the user was already on the list of viewers, this method promotes the user out of the list of viewers.
Parameters
Name Type Description
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
addEditor(user)
Adds the given user to the list of editors for the Spreadsheet (#). If the user was already on the list of viewers, this method promotes the user out of the list of viewers.
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
addEditors(emailAddresses)
Adds the given array of users to the list of editors for the Spreadsheet (#). If any of the users were already on the list of viewers, this method promotes them out of the list of viewers.
Parameters
Name Type Description
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
addMenu(name, subMenus)
Each menu entry runs a user-de ned function. Usually, you want to call it from the onOpen() function so that the menu is automatically created when the spreadsheet is loaded.
ss.addMenu("addMenuExample", menuEntries);
}
Parameters
subMenus Object[] An array of JavaScript maps with name and functionName parameters. You can use functions from included libraries, such as Library.libFunction1.
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
addViewer(emailAddress)
Adds the given user to the list of viewers for the Spreadsheet (#). If the user was already on the list of editors, this method has no effect.
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
addViewer(user)
Adds the given user to the list of viewers for the Spreadsheet (#). If the user was already on the list of editors, this method has no effect.
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
addViewers(emailAddresses)
Adds the given array of users to the list of viewers for the Spreadsheet (#). If any of the users were already on the list of editors, this method has no effect for them.
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
appendRow(rowContents)
Appends a row to the spreadsheet. This operation is atomic; it prevents issues where a user asks for the last row, and then writes to that row, and an intervening mutation occurs between getting the last row and writing to it.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
rowContents Object[] An array of values to insert after the last row in the sheet.
Return
Sheet (https://developers.google.com/apps-script/reference/spreadsheet/sheet.html) — the sheet, useful for method chaining
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
autoResizeColumn(columnPosition)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
copy(name)
// This code makes a copy of the current spreadsheet and names it appropriately
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.copy("Copy of " + ss.getName());
Parameters
name String
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
createDeveloperMetadataFinder()
Returns a DeveloperMetadataFinderApi for nding developer metadata within the scope of this spreadsheet. By default this considers all metadata associated with the spreadsheet, sheets, rows, and columns.
Return
DeveloperMetadataFinder (https://developers.google.com/apps-script/reference/spreadsheet/developer-metadata- nder.html) — A developer metadata nder to search for metadata in the scope of this spreadsheet.
createTextFinder(findText)
Creates a text nder for the spreadsheet, which can be used to nd and replace text within the spreadsheet. The search starts from the rst sheet of the spreadsheet.
// Replaces the last found occurrence of 'dog' with 'cat' and returns the number
// of occurrences replaced.
var numOccurrencesReplaced = findOccurrence.replaceWith('cat');
Parameters
Return
deleteActiveSheet()
// The code below deletes the currently active sheet and stores the new active sheet in a
// variable
var newSheet = SpreadsheetApp.getActiveSpreadsheet().deleteActiveSheet();
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
deleteColumn(columnPosition)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Columns start at "1" - this deletes the first column
sheet.deleteColumn(1);
Parameters
columnPosition Integer The position of the column, starting at 1 for the rst column.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
deleteColumns(columnPosition, howMany)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Columns start at "1" - this deletes the first two columns
sheet.deleteColumns(1, 2);
Parameters
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
deleteRow(rowPosition)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Rows start at "1" - this deletes the first row
sheet.deleteRow(1);
Parameters
rowPosition Integer The position of the row, starting at 1 for the rst row.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
deleteRows(rowPosition, howMany)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Rows start at "1" - this deletes the first two rows
sheet.deleteRows(1, 2);
Parameters
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
deleteSheet(sheet)
Deletes the speci ed sheet.
Parameters
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
duplicateActiveSheet()
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getActiveCell()
Note: It's preferrable to use getCurrentCell() (#getCurrentCell()), which the returns the current highlighted cell.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Returns the active cell
var cell = sheet.getActiveCell();
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getActiveRange()
Returns the selected range in the active sheet, or null if there is no active range. If multiple ranges are selected this method returns only the last selected range.
The term "active range" refers to the range that a user has selected in the active sheet, but in a custom function it refers to the cell being actively recalculated.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
See also
setActiveRange(range) (#setActiveRange(Range))
getActiveRangeList()
Returns the list of active ranges in the active sheet or null if there are no active ranges.
If there is a single range selected, this behaves as a getActiveRange() (#getActiveRange()) call.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
See also
setActiveRangeList(rangeList) (#setActiveRangeList(RangeList))
getActiveSheet()
The active sheet in a spreadsheet is the sheet that is being displayed in the spreadsheet UI.
Return
getAs(contentType)
Return the data inside this object as a blob converted to the speci ed content type. This method adds the appropriate extension to the lename—for example, "my le.pdf". However, it assumes that the part of the lename that
follows the last period (if any) is an existing extension that should be replaced. Consequently, "ShoppingList.12.25.2014" becomes "ShoppingList.12.25.pdf".
Parameters
contentType String The MIME type to convert to. For most blobs, 'application/pdf' is the only valid option. For images in BMP, GIF, JPEG, or PNG format, any of 'image/bmp', 'image/gif', 'image/jpeg', or 'image/png' are also valid.
Return
getBandings()
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getBlob()
Return
getColumnWidth(columnPosition)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Columns start at 1
Logger.log(sheet.getColumnWidth(1));
Parameters
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getCurrentCell()
Returns the current cell in the active sheet or null if there is no current cell. The current cell is the cell that has focus in the Google Sheets UI, and is highlighted by a dark border. There is never more than one current cell. When a
user selects one or more cell ranges, one of the cells in the selection is the current cell.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getDataRange()
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getDataSourceTables()
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getDeveloperMetadata()
Return
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getEditors()
Gets the list of editors for this Spreadsheet (#). If the user who executes the script does not have edit access to the Spreadsheet (#), this method throws an exception.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getFormUrl()
Returns the URL for the form that sends its responses to this spreadsheet, or null if this spreadsheet has no associated form. If multiple forms send responses to this spreadsheet, the form URL returned is indeterminate. As an
alternative, per sheet form URL associations can be retrieved through the Sheet.getFormUrl() (https://developers.google.com/apps-script/reference/spreadsheet/sheet.html#getFormUrl()) method.
Return
String — The URL for the form that places its responses in this spreadsheet, or null if this spreadsheet doesn't have an associated form.
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getFrozenColumns()
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getFrozenRows()
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getId()
Gets a unique identi er for this spreadsheet. A spreadsheet ID can be extracted from its URL. For example, the spreadsheet ID in the URL https://docs.google.com/spreadsheets/d/abc1234567/edit#gid=0 is "abc1234567".
getImages()
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getIterativeCalculationConvergenceThreshold()
Returns the threshold value used during iterative calculation. When the results of successive calculation differ by less than this value, the iterative calculation stops.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getLastColumn()
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// This logs the value in the very last cell of this sheet
var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var lastCell = sheet.getRange(lastRow, lastColumn);
Logger.log(lastCell.getValue());
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getLastRow()
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// This logs the value in the very last cell of this sheet
var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var lastCell = sheet.getRange(lastRow, lastColumn);
Logger.log(lastCell.getValue());
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getMaxIterativeCalculationCycles()
Return
Integer — The maximum number of calculation iterations.
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getName()
var ss = SpreadsheetApp.getActiveSpreadsheet();
Logger.log(ss.getName());
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getNamedRanges()
// The code below logs the name of the first named range.
var namedRanges = SpreadsheetApp.getActiveSpreadsheet().getNamedRanges();
if (namedRanges.length > 1) {
Logger.log(namedRanges[0].getName());
}
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getNumSheets()
// The code below logs the number of sheets in the active spreadsheet.
Logger.log(SpreadsheetApp.getActiveSpreadsheet().getNumSheets());
Return
getOwner()
Returns the owner of the document, or null for a document in a shared drive.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var owner = ss.getOwner();
Logger.log(owner.getEmail());
Return
User (https://developers.google.com/apps-script/reference/base/user.html) — The owner of the document, or null if the document is in a shared drive.
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getProtections(type)
Gets an array of objects representing all protected ranges or sheets in the spreadsheet.
// Remove all range protections in the spreadsheet that the user has permission to edit.
var ss = SpreadsheetApp.getActive();
var protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE);
for (var i = 0; i < protections.length; i++) {
var protection = protections[i];
if (protection.canEdit()) {
protection.remove();
}
}
// Remove all sheet protections in the spreadsheet that the user has permission to edit.
var ss = SpreadsheetApp.getActive();
var protections = ss.getProtections(SpreadsheetApp.ProtectionType.SHEET);
for (var i = 0; i < protections.length; i++) {
var protection = protections[i];
if (protection.canEdit()) {
protection.remove();
}
}
Parameters
NameType Description
Return
Protection[] (https://developers.google.com/apps-script/reference/spreadsheet/protection.html) — An array of objects representing all protected ranges or sheets in the spreadsheet.
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getRange(a1Notation)
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getRangeByName(name)
Returns a named range, or null if no range with the given name is found. If multiple sheets of the spreadsheet use the same range name, specify the sheet name without additional quotation marks — for example,
getRangeByName('TaxRates') or getRangeByName('Sheet Name!TaxRates'), but not getRangeByName('"Sheet Name"!TaxRates').
// Log the number of columns for the range named 'TaxRates' in the active spreadsheet.
var range = SpreadsheetApp.getActiveSpreadsheet().getRangeByName('TaxRates');
if (range != null) {
Logger.log(range.getNumColumns());
}
Parameters
Return
getRangeList(a1Notations)
Returns the RangeList (https://developers.google.com/apps-script/reference/spreadsheet/range-list.html) collection representing the ranges in the same sheet speci ed by a non-empty list of A1 notations or R1C1 notations.
// Get a list of ranges A1:D4, F1:H4.
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var rangeList = sheet.getRangeList(['A1:D4', 'F1:H4']);
Parameters
a1Notations String[] The list of ranges to return, as speci ed in A1 notation or R1C1 notation.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getRecalculationInterval()
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getRowHeight(rowPosition)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Rows start at 1
Logger.log(sheet.getRowHeight(1));
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getSelection()
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getSheetByName(name)
If multiple sheets have the same name, the leftmost one is returned. Returns null if there is no sheet with the given name.
// The code below logs the index of a sheet named "Expenses"
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Expenses");
if (sheet != null) {
Logger.log(sheet.getIndex());
}
Parameters
Return
getSheetId()
This is an ID for the sheet that is unique to the spreadsheet. The ID is a monotonically increasing integer assigned at sheet creation time that is independent of sheet position. This is useful in conjunction with methods such as
Range.copyFormatToRange(gridId, column, columnEnd, row, rowEnd) (https://developers.google.com/apps-script/reference/spreadsheet/range.html#copyFormatToRange(Integer,Integer,Integer,Integer,Integer)) that take a gridId
parameter rather than a Sheet (https://developers.google.com/apps-script/reference/spreadsheet/sheet.html) instance.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Logger.log(sheet.getSheetId());
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getSheetName()
Logger.log(sheet.getSheetName());
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
Returns the rectangular grid of values for this range starting at the given coordinates. A -1 value given as the row or column position is equivalent to getting the very last row or column that has data in the sheet.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
Return
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getSheets()
Return
getSpreadsheetLocale()
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getSpreadsheetTimeZone()
Return
String — The time zone, speci ed in "long" format (for example, "America/New_York", as listed by Joda.org (http://joda-time.sourceforge.net/timezones.html)).
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getUrl()
var ss = SpreadsheetApp.getActiveSpreadsheet();
Logger.log(ss.getUrl());
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
getViewers()
Gets the list of viewers and commenters for this Spreadsheet (#). If the user who executes the script does not have edit access to the Spreadsheet (#), this method throws an exception.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
hideColumn(column)
Hides the columns in the given range.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
hideRow(row)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
insertColumnAfter(afterPosition)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
afterPosition Integer The column after which the new column should be added.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
insertColumnBefore(beforePosition)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
insertColumnsAfter(afterPosition, howMany)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
afterPosition Integer The column after which the new column should be added.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
insertColumnsBefore(beforePosition, howMany)
Inserts a number of columns before the given column position.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
beforePosition Integer The column before which the new column should be added.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
Inserts a Spreadsheet (#) as an image in the document at a given row and column. The image size is retrieved from the blob contents.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
blobSource BlobSource (https://developers.google.com/apps-script/reference/base/blob-source.html) The blob containing the image contents, MIME type, and (optionally) name.
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
Inserts a Spreadsheet (#) as an image in the document at a given row and column, with a pixel offset. The image size is retrieved from the blob contents.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
blobSource BlobSource (https://developers.google.com/apps-script/reference/base/blob-source.html) The blob containing the image contents, MIME type, and (optionally) name.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
insertImage(url, column, row)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
sheet.insertImage("https://www.google.com/images/srpr/logo3w.png", 1, 1);
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
Inserts an image in the document at a given row and column, with a pixel offset.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
insertRowAfter(afterPosition)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
afterPosition Integer The row after which the new row should be added.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
insertRowBefore(beforePosition)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
beforePosition Integer The row before which the new row should be added.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
insertRowsAfter(afterPosition, howMany)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
insertRowsBefore(beforePosition, howMany)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
beforePosition Integer The row before which the new rows should be added.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
insertSheet()
Inserts a new sheet into the spreadsheet, using a default sheet name. The new sheet becomes the active sheet.
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.insertSheet();
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
insertSheet(sheetIndex)
Inserts a new sheet into the spreadsheet at the given index. The new sheet becomes the active sheet.
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.insertSheet(1);
Parameters
sheetIndex Integer The index of the newly created sheet. To insert a sheet as the rst one in the spreadsheet, set it to 0.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
insertSheet(sheetIndex, options)
Inserts a new sheet into the spreadsheet at the given index and uses optional advanced arguments. The new sheet becomes the active sheet.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var templateSheet = ss.getSheetByName('Sales');
ss.insertSheet(1, {template: templateSheet});
Parameters
sheetIndex Integer The index of the newly created sheet. To insert a sheet as the rst one in the spreadsheet, set it to 0.
Advanced parameters
template Sheet (https://developers.google.com/apps-script/reference/spreadsheet/sheet.html) All data from the template sheet object is copied to the new sheet. The sheet template must be one of the sheets of the Spreadsheet object.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
insertSheet(options)
Inserts a new sheet into the spreadsheet, using a default sheet name and optional advanced arguments. The new sheet becomes the active sheet.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var templateSheet = ss.getSheetByName('Sales');
ss.insertSheet({template: templateSheet});
Parameters
Name Type Description
Advanced parameters
template Sheet (https://developers.google.com/apps-script/reference/spreadsheet/sheet.html) All data from the template sheet object is copied to the new sheet. The sheet template must be one of the sheets of this Spreadsheet object.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
insertSheet(sheetName)
Inserts a new sheet into the spreadsheet with the given name. The new sheet becomes the active sheet.
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.insertSheet('My New Sheet');
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
insertSheet(sheetName, sheetIndex)
Inserts a new sheet into the spreadsheet with the given name at the given index. The new sheet becomes the active sheet.
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.insertSheet('My New Sheet', 1);
Parameters
sheetIndex Integer The index of the newly created sheet. To insert a sheet as the rst one in the spreadsheet, set it to 0.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
Inserts a new sheet into the spreadsheet with the given name at the given index and uses optional advanced arguments. The new sheet becomes the active sheet.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var templateSheet = ss.getSheetByName('Sales');
ss.insertSheet('My New Sheet', 1, {template: templateSheet});
Parameters
sheetIndex Integer The index of the newly inserted sheet. To insert a sheet as the rst one in a spreadsheet, set it to 0.
options Object Optional JavaScript advanced arguments.
Advanced parameters
template Sheet (https://developers.google.com/apps-script/reference/spreadsheet/sheet.html) All data from the template sheet object is copied to the new sheet. The sheet template must be one of the sheets of the Spreadsheet object.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
insertSheet(sheetName, options)
Inserts a new sheet into the spreadsheet with the given name and uses optional advanced arguments. The new sheet becomes the active sheet.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var templateSheet = ss.getSheetByName('Sales');
ss.insertSheet('My New Sheet', {template: templateSheet});
Parameters
Advanced parameters
template Sheet (https://developers.google.com/apps-script/reference/spreadsheet/sheet.html) All data from the template sheet object is copied to the new sheet. The sheet template must be one of the sheets of the Spreadsheet object.
Return
Sheet (https://developers.google.com/apps-script/reference/spreadsheet/sheet.html) — The new sheet.
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
insertSheetWithDataSourceTable(spec)
Inserts a new sheet in the spreadsheet, creates a DataSourceTable (https://developers.google.com/apps-script/reference/spreadsheet/data-source-table.html) spanning the entire sheet with the given data source speci cation, and starts
data execution. As a side effect, makes the new sheet the active sheet.
Throws an exception if the data source type is not enabled. Use SpreadsheetApp#enable...Execution() methods to enable data execution for speci c data source type.
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
isColumnHiddenByUser(columnPosition)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Columns start at 1
Logger.log(sheet.isColumnHiddenByUser(1));
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
isIterativeCalculationEnabled()
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
isRowHiddenByFilter(rowPosition)
Returns whether the given row is hidden by a lter (not a lter view).
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Columns start at 1
Logger.log(sheet.isColumnHiddenByUser(1));
Parameters
Name Type Description
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
isRowHiddenByUser(rowPosition)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// Rows start at 1
Logger.log(sheet.isRowHiddenByUser(1));
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
moveActiveSheet(pos)
Moves the active sheet to the given position in the list of sheets. Throws an exception if the position is negative or greater than the number of sheets.
spreadsheet.moveActiveSheet(2);
Parameters
pos Integer A position to move the active sheet to in the list of sheets.
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
moveChartToObjectSheet(chart)
Creates a new SheetType.OBJECT (https://developers.google.com/apps-script/reference/spreadsheet/sheet-type.html#OBJECT) sheet and moves the provided chart to it. If the chart is already on its own sheet, that sheet is returned
without creating a new one.
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
removeEditor(emailAddress)
Removes the given user from the list of editors for the Spreadsheet (#). This method does not block users from accessing the Spreadsheet (#) if they belong to a class of users who have general access—for example, if the
Spreadsheet (#) is shared with the user's entire domain.
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
removeEditor(user)
Removes the given user from the list of editors for the Spreadsheet (#). This method does not block users from accessing the Spreadsheet (#) if they belong to a class of users who have general access—for example, if the
Spreadsheet (#) is shared with the user's entire domain.
Parameters
Name Type Description
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
removeMenu(name)
Removes a menu that was added by addMenu(name, subMenus) (#addMenu(String,Object)). The name argument should have the same value as the corresponding call to addMenu(name, subMenus) (#addMenu(String,Object)).
Parameters
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
removeNamedRange(name)
Deletes a named range with the given name. Throws an exception if no range with the given name is found in the spreadsheet.
// The code below creates a new named range "foo", and then remove it.
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.setNamedRange("foo", ss.getActiveRange());
ss.removeNamedRange("foo");
Parameters
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
removeViewer(emailAddress)
Removes the given user from the list of viewers and commenters for the Spreadsheet (#). This method has no effect if the user is an editor, not a viewer or commenter. This method also does not block users from accessing the
Spreadsheet (#) if they belong to a class of users who have general access—for example, if the Spreadsheet (#) is shared with the user's entire domain.
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
removeViewer(user)
Removes the given user from the list of viewers and commenters for the Spreadsheet (#). This method has no effect if the user is an editor, not a viewer. This method also does not block users from accessing the Spreadsheet
(#) if they belong to a class of users who have general access—for example, if the Spreadsheet (#) is shared with the user's entire domain.
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
rename(newName)
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.rename("This is the new name");
Parameters
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
renameActiveSheet(newName)
Parameters
newName String The new name for the current active sheet.
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
setActiveRange(range)
Sets the speci ed range as the active range (#getActiveRange()) in the active sheet, with the top left cell in the range as the current cell (#getCurrentCell()).
Parameters
Return
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
setActiveRangeList(rangeList)
Sets the speci ed list of ranges as the active ranges (#getActiveRangeList()) in the active sheet. The last range in the list is set as the active range (#getActiveRange()).
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
setActiveSelection(range)
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
setActiveSelection(a1Notation)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
sheet.setActiveSelection("A1:D4");
Parameters
a1Notation String The range to set as active, as speci ed in A1 notation or R1C1 notation.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
setActiveSheet(sheet)
Sets the given sheet to be the active sheet in the spreadsheet. The Google Sheets UI displays the chosen sheet unless the sheet belongs to a different spreadsheet.
// The code below makes the first sheet active in the active spreadsheet.
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
spreadsheet.setActiveSheet(spreadsheet.getSheets()[0]);
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
setActiveSheet(sheet, restoreSelection)
Sets the given sheet to be the active sheet in the spreadsheet, with an option to restore the most recent selection within that sheet. The Google Sheets UI displays the chosen sheet unless the sheet belongs to a different
spreadsheet.
Parameters
restoreSelectionBoolean Tf true, the most recent selection of the new active sheet becomes selected again as the new sheet becomes active; if false, the new sheet becomes active
without changing the current selection.
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
setColumnWidth(columnPosition, width)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
setCurrentCell(cell)
If the speci ed cell is present in an already selected range, then that range becomes the active range with the cell as the current cell.
If the speci ed cell is not present in any selected range, then any existing selection is removed and the cell becomes the current cell and the active range.
Note:The speci ed Range (https://developers.google.com/apps-script/reference/spreadsheet/range.html) must consist of one cell, otherwise it throws an exception.
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
setFrozenColumns(columns)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
setFrozenRows(rows)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
setIterativeCalculationConvergenceThreshold(minThreshold)
Sets the minimum threshold value for iterative calculation. When the results of successive calculation differ by less than this value, the iterative calculation stops. This value must be non-negative, and defaults to 0.05.
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
setIterativeCalculationEnabled(isEnabled)
Sets whether iterative calculation is enabled in this spreadsheet. If the maximum number of calculation cycles and convergence threshold have not previously been set when the calculation is enabled, they default to 50 and 0.05
respectively. If either has been set previously, they retain their previous values.
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
setMaxIterativeCalculationCycles(maxIterations)
Sets the maximum number of calculation iterations that should be performed during iterative calculation. This value must be between 1 and 10,000 (inclusive), and defaults to 50.
Parameters
maxIterations Integer The maximum number of calculation iterations (between 1 and 10,000).
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
setNamedRange(name, range)
Names a range.
// The code below creates a new named range "TaxRates" in the active spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.setNamedRange("TaxRates", SpreadsheetApp.getActiveRange());
Parameters
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
setRecalculationInterval(recalculationInterval)
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
setRowHeight(rowPosition, height)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
setSpreadsheetLocale(locale)
Parameters
locale String The locale code to use (for example, 'en', 'fr', or 'en_US').
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
setSpreadsheetTimeZone(timezone)
Parameters
timezone String The time zone, speci ed in "long" format (for example, "America/New_York", as listed by Joda.org (http://joda-time.sourceforge.net/timezones.html)).
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
show(userInterface)
Displays a custom user interface component in a dialog centered in the user's browser's viewport. The server-side script's execution is not suspended. To communicate with the server side, the user interface component must
make asynchronous callbacks to the server-side script.
If the server-side script previously displayed a dialog that has not yet been dismissed, then the existing dialog is replaced with the newly requested dialog's user interface.
The following code snippet displays a simple HtmlService (https://developers.google.com/apps-script/reference/html/html-service.html) application in a dialog with the speci ed title, height, and width:
SpreadsheetApp.getActiveSpreadsheet().show(htmlApp);
Parameters
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/script.container.ui
sort(columnPosition)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
Name Type Description
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
sort(columnPosition, ascending)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
toast(msg)
Shows a popup window in the lower right corner of the spreadsheet with the given message.
Parameters
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
toast(msg, title)
Shows a popup window in the lower right corner of the spreadsheet with the given message and title.
// Show a popup with the title "Status" and the message "Task started".
SpreadsheetApp.getActiveSpreadsheet().toast('Task started', 'Status');
Parameters
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
toast(msg, title, timeoutSeconds)
Shows a popup window in the lower right corner of the spreadsheet with the given title and message, that stays visible for a certain length of time.
// Show a 3-second popup with the title "Status" and the message "Task started".
SpreadsheetApp.getActiveSpreadsheet().toast('Task started', 'Status', 3);
Parameters
timeoutSeconds Number The timeout in seconds; if null, the toast defaults to 5 seconds; if negative, the toast remains until dismissed.
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
unhideColumn(column)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
unhideRow(row)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
Parameters
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
updateMenu(name, subMenus)
Updates a menu that was added by addMenu(name, subMenus) (#addMenu(String,Object)). Works exactly like addMenu(name, subMenus) (#addMenu(String,Object)).
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [];
menuEntries.push({name: "Lone Menu Entry", functionName: "function1"});
ss.updateMenu("addMenuExample", menuEntries);
Parameters
subMenus Object[] An array of JavaScript maps with name and functionName parameters. You can use functions from included libraries, such as Library.libFunction1.
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
Deprecated methods
getSheetProtection()
Deprecated. For spreadsheets created in the newer version of Google Sheets, use Sheet.getProtections(type) (https://developers.google.com/apps-script/reference/spreadsheet/sheet.html#getProtections(ProtectionType)), which returns the more
powerful Protection (https://developers.google.com/apps-script/reference/spreadsheet/protection.html) class. Although this method is deprecated, it remains available for compatibility with the older version of Sheets
Returns a PageProtection (https://developers.google.com/apps-script/reference/spreadsheet/page-protection.html) instance describing the permissions for the current sheet.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
permissions.setProtected(true);
permissions.addUser("[email protected]");
// Logs the users that have access to edit this sheet. Note that this
// is different from access to the entire spreadsheet - getUsers()
// only returns users if permissions.isProtected() is set to true.
var users = permissions.getUsers();
Logger.log(users);
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
isAnonymousView()
Deprecated. As of January 2014 this function is deprecated and not available in the new version of Google Sheets.
Indicates whether the document allows anonymous viewing. As this is no longer supported in the new version of Google Sheets (https://support.google.com/drive/answer/3541068), use File.getSharingAccess()
(https://developers.google.com/apps-script/reference/drive/ le.html#getSharingAccess()) and File.getSharingPermission() (https://developers.google.com/apps-script/reference/drive/ le.html#getSharingPermission()) instead.
// Determine if the document allows anonymous viewing via the Drive API.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var file = DriveApp.getFileById(ss.getId());
var access = file.getSharingAccess();
var permission = file.getSharingPermission();
var isAnonymousAccess =
access == DriveApp.Access.ANYONE || access == DriveApp.Access.ANYONE_WITH_LINK;
var isAnonymousEdit = isAnonymousAccess && permission != DriveApp.Permission.NONE;
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
See also
Drive Service (https://developers.google.com/apps-script/reference/drive/)
isAnonymousWrite()
Deprecated. As of January 2014 this function is deprecated and not available in the new version of Google Sheets.
Indicates whether the document allows edits from anonymous users. As this is no longer supported in the new version of Google Sheets (https://support.google.com/drive/answer/3541068), use File.getSharingAccess()
(https://developers.google.com/apps-script/reference/drive/ le.html#getSharingAccess()) and File.getSharingPermission() (https://developers.google.com/apps-script/reference/drive/ le.html#getSharingPermission()) instead.
// Determine if the document allow anonymous edits via the Drive API.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var file = DriveApp.getFileById(ss.getId());
var access = file.getSharingAccess();
var permission = file.getSharingPermission();
var isAnonymousAccess =
access == DriveApp.Access.ANYONE || access == DriveApp.Access.ANYONE_WITH_LINK;
var isAnonymousEdit = isAnonymousAccess && permission == DriveApp.Permission.EDIT;
Return
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
See also
Drive Service (https://developers.google.com/apps-script/reference/drive/)
setAnonymousAccess(anonymousReadAllowed, anonymousWriteAllowed)
Deprecated. As of January 2014 this function is deprecated and not available in the new version of Google Sheets.
Sets the document's policy on anonymous reading and writing. As this is no longer supported in the new version of Google Sheets (https://support.google.com/drive/answer/3541068), use File.setSharing(accessType,
permissionType) (https://developers.google.com/apps-script/reference/drive/ le.html#setSharing(Access,Permission)) as an alternative.
// Set the document's policy on anonymous reading and writing via the Drive API.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var file = DriveApp.getFileById(ss.getId());
Parameters
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
https://www.googleapis.com/auth/spreadsheets.currentonly
https://www.googleapis.com/auth/spreadsheets
See also
isAnonymousView() (#isAnonymousView())
isAnonymousWrite() (#isAnonymousWrite())
Drive Service (https://developers.google.com/apps-script/reference/drive/)
setSheetProtection(permissions)
Deprecated. For spreadsheets created in the newer version of Google Sheets, use Sheet.protect() (https://developers.google.com/apps-script/reference/spreadsheet/sheet.html#protect()), which returns the more powerful Protection
(https://developers.google.com/apps-script/reference/spreadsheet/protection.html) class. Although this method is deprecated, it remains available for compatibility with the older version of Sheets
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
// This copies the permissions on the first sheet to the second sheet
var sheetToClonePermissionsTo = ss.getSheets()[1];
sheetToClonePermissionsTo.setSheetProtection(permissions);
Parameters
Authorization
Scripts that use this method require authorization with one or more of the following scopes (https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):
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 the Creative Commons Attribution 4.0 License (https://creativecommons.org/licenses/by/4.0/), and code samples are licensed under the Apache 2.0 License
(https://www.apache.org/licenses/LICENSE-2.0). For details, see our Site Policies (https://developers.google.com/terms/site-policies). Java is a registered trademark of Oracle and/or its a liates.
Last updated May 20, 2019.