Skip to content

Instantly share code, notes, and snippets.

@prasanthmj
Created April 27, 2019 05:28
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
How to get cell value in Google Sheets using apps script. See article here: http://blog.gsmart.in/google-sheet-script-get-cell-value/
function onOpen()
{
var ui = SpreadsheetApp.getUi();
ui.createMenu('GetValues')
.addItem('get current', 'getCurrentCellValue')
.addItem('get by row col', 'getByRowAndColumn')
.addItem('get by address a1', 'getByCellAddressA1Notation')
.addToUi();
}
function getCurrentCellValue()
{
var cell = SpreadsheetApp.getActiveSheet().getActiveCell();
var a1 = cell.getA1Notation();
var val = cell.getValue();
SpreadsheetApp.getUi().alert("The active cell "+a1+" value is "+val);
}
function getByRowAndColumn()
{
var ui = SpreadsheetApp.getUi();
var response = ui.prompt(
'Cell address',
'Please enter the cell address in this format: row,col for example, 5,2 means row 5 col 2',
ui.ButtonSet.OK);
var resp_text = response.getResponseText();
var match = resp_text.match(/^(\d+)\,(\d+)/);
var row = parseInt(match[1]);
var col = parseInt(match[2]);
var value = SpreadsheetApp.getActiveSheet().getRange(row,col).getValue();
SpreadsheetApp.getUi().alert("The value is "+value);
}
function getByCellAddressA1Notation()
{
var ui = SpreadsheetApp.getUi();
var response = ui.prompt(
'Cell address',
'Please enter the cell address (A1 notation)',
ui.ButtonSet.OK);
var a1 = response.getResponseText();
var value = SpreadsheetApp.getActiveSheet().getRange(a1).getValue();
ui.alert("cell value "+value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment