A very basic question for google apps script: How do I reference the current cell from which the app script is being called for this current or active sheet in this spreadsheet?
You do the proper thing - work on an array of the Range's values - as opposed to repeatedly call over the interface via getCell or similar just to check the value. To reference the cell whose value is values[r][c] , note that the Javascript array is 0-base and the Range is 1-base indexed. So A1 = [0][0].
Get selected cell value in your Google Sheet Script Now we have to add getCurrentCellValue() function. This function will get the value of the currently selected cell and then show it in a message box. In order to make it a little more informative, let us show the cell's A1 notation and then its value.
/**
* Get selected cell coordinates and value, then set the cell value to 100
*/
function cellTester() {
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getActiveSheet();
var cellRange = sheet.getActiveCell();
var selectedColumn = cellRange.getColumn();
var selectedRow = cellRange.getRow();
Logger.log(`selectedColumn: ${selectedColumn}`);
Logger.log(`selectedRow: ${selectedRow}`);
Logger.log(`selected cell vale: ${cellRange.getValue()}`);
cellRange.setValue(100);
}
Log di Stackdriver
20 apr 2020, 23:23:56 Informazioni selectedColumn: 3
20 apr 2020, 23:23:56 Informazioni selectedRow: 2
20 apr 2020, 23:23:56 Informazioni selected cell vale: 69
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With