Class Sheet

  • The Sheet object in Google Apps Script provides extensive methods for accessing and modifying individual sheets within a spreadsheet.

  • You can perform common operations like activating, hiding/showing, and clearing sheet content and formatting.

  • The object allows for detailed manipulation of sheet structure, including inserting, deleting, and moving columns and rows.

  • It offers methods to get and set metadata, manage ranges and selections, control formatting and display options, work with groups, and interact with embedded objects like charts and images.

  • Many methods require specific authorization scopes to execute successfully.

Sheet

Access and modify spreadsheet sheets. Common operations are renaming a sheet and accessing range objects from the sheet.

Methods

MethodReturn typeBrief description
activate()SheetActivates this sheet.
addDeveloperMetadata(key)SheetAdds developer metadata with the specified key to the sheet.
addDeveloperMetadata(key, visibility)SheetAdds developer metadata with the specified key and visibility to the sheet.
addDeveloperMetadata(key, value)SheetAdds developer metadata with the specified key and value to the sheet.
addDeveloperMetadata(key, value, visibility)SheetAdds developer metadata with the specified key, value, and visibility to the sheet.
appendRow(rowContents)SheetAppends a row to the bottom of the current data region in the sheet.
asDataSourceSheet()DataSourceSheet|nullReturns the sheet as a DataSourceSheet if the sheet is of type SheetType.DATASOURCE, or null otherwise.
autoResizeColumn(columnPosition)SheetSets the width of the given column to fit its contents.
autoResizeColumns(startColumn, numColumns)SheetSets the width of all columns starting at the given column position to fit their contents.
autoResizeRows(startRow, numRows)SheetSets the height of all rows starting at the given row position to fit their contents.
clear()SheetClears the sheet of content and formatting information.
clear(options)SheetClears the sheet of contents and/or format, as specified with the given advanced options.
clearConditionalFormatRules()voidRemoves all conditional format rules from the sheet.
clearContents()SheetClears the sheet of contents, while preserving formatting information.
clearFormats()SheetClears the sheet of formatting, while preserving contents.
clearNotes()SheetClears the sheet of all notes.
collapseAllColumnGroups()SheetCollapses all column groups on the sheet.
collapseAllRowGroups()SheetCollapses all row groups on the sheet.
copyTo(spreadsheet)SheetCopies the sheet to a given spreadsheet, which can be the same spreadsheet as the source.
createDeveloperMetadataFinder()DeveloperMetadataFinderReturns a DeveloperMetadataFinder for finding developer metadata within the scope of this sheet.
createTextFinder(findText)TextFinderCreates a text finder for the sheet, which can find and replace text within the sheet.
deleteColumn(columnPosition)SheetDeletes the column at the given column position.
deleteColumns(columnPosition, howMany)voidDeletes a number of columns starting at the given column position.
deleteRow(rowPosition)SheetDeletes the row at the given row position.
deleteRows(rowPosition, howMany)voidDeletes a number of rows starting at the given row position.
expandAllColumnGroups()SheetExpands all column groups on the sheet.
expandAllRowGroups()SheetExpands all row groups on the sheet.
expandColumnGroupsUpToDepth(groupDepth)SheetExpands all column groups up to the given depth, and collapses all others.
expandRowGroupsUpToDepth(groupDepth)SheetExpands all row groups up to the given depth, and collapses all others.
getActiveCell()RangeReturns the active cell in this sheet.
getActiveRange()RangeReturns the selected range in the active sheet, or null if there is no active range.
getActiveRangeList()RangeList|nullReturns the list of active ranges in the active sheet or null if there are no active ranges.
getBandings()Banding[]Returns all the bandings in this sheet.
getCharts()EmbeddedChart[]Returns an array of charts on this sheet.