class SpreadsheetApp method .getNumColumns()

SpreadsheetApp is the Apps Script service.

.getNumColumns() is the method name you will see after a dot in your code.

What it does

Returns how many columns are in a range.

Why it's used

  • Iterate columns in a dynamic range without guessing width.
  • Build column headers from the range size.

Common errors

  • Forgetting parentheses on getNumColumns. Write SpreadsheetApp.getNumColumns(), not SpreadsheetApp.getNumColumns or getNumColumns by itself.
  • Skipping dots between chained calls. Each step needs a dot, like SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Data').getNumColumns().
  • Adding spaces where they do not belong. Write SpreadsheetApp.getNumColumns(), not SpreadsheetApp .getNumColumns(), SpreadsheetApp.getNumColumns (), or SpreadsheetApp . getNumColumns().
  • Wrong capitalization. Use SpreadsheetApp and getNumColumns, not spreadsheetapp or getnumcolumns.

Explore

Related methods

  • .getNumRows()

    Returns how many rows are in a range.

  • .getMaxColumns()

    Returns the total number of columns the sheet can hold.

  • .getColumn()

    Returns the starting column index of a range.

  • .getRange()

    Returns a range of cells by A1 notation or row and column numbers.

  • .getLastColumn()

    Returns the column number of the last column that has content.

Better Sheets tutorials

No tagged tutorials yet. Fetch Apps Script from the harvest table and this page fills automatically.

Related blog posts

Written guides about SpreadsheetApp.getNumColumns().

Browse the blog