Created
April 27, 2019 05:28
-
-
Save prasanthmj/4fcee6c6e3c4d3f0bbdbf725db04a937 to your computer and use it in GitHub Desktop.
How to get cell value in Google Sheets using apps script. See article here: http://blog.gsmart.in/google-sheet-script-get-cell-value/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
hello,
how can i call this script by url ? .. lik my url is: https://script.google.com/macros/s/xxxxxxxxxxxxxxxxxxx/exec ; now what should i put after the /exec to het the value on my cell browser ?