Skip to main content

Acquire range values

Explains how to get a specific range value from the spreadsheet.

Function to use

Spreadsheet.getSheetValues([Start row], [Start column], [Number of rows], [Number of columns]);

Use GetSheetValues method provided in Spreadsheet class.

It requires four arguments, and specifies the start row, start column, number of rows, and number of columns, respectively.

For example, if you want to get a 4x5 range from the cell C2 of the target sheet, you must specify it as GetSheetValues(2, 3, 4, 5).

The return value can be received as an array of the string sequence String[][].

You may need to authenticate at the first execution because you will access the spreadsheet when execution.

Sample code

/**
* Target spreadsheet ID
* https://docs.google.com/spreadsheets/d/〇〇〇/edit Part of 〇〇〇
*/
const SPREAD_SHEET_ID = '_______________';

/**
* Set the height of the cell by specifying the numerical value
*/
const getSheetValues = () => {
/** Target spreadsheet */
const ss = SpreadsheetApp.openById(SPREAD_SHEET_ID);

/** Target sheet */
const sheet = ss.getSheetByName('シート1');

/** get data */
const arrays = sheet.getSheetValues(2, 3, 4, 5);

console.log(arrays);
return arrays;
};

When executed, the scope of 4x5 is returned from C2 for the specified spreadsheet.