Getting the cursor row/column from a Google spreadsheet through a Javascript method

拈花ヽ惹草 提交于 2019-12-01 11:10:56
Peter Herrmann

The following code works for me. It prompts me with the row number of my current position in the spreaadsheet:

function onOpen() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var menuEntries = [ {name: "Test1", functionName: "menuItem1"}];
  ss.addMenu("Tests", menuEntries);
}

function menuItem1() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  Browser.msgBox("You have selected row " + ss.getActiveCell().getRow());
}

Have you tried a simple function like this one ?

function getRCposition(){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var cell = ss.getActiveCell();
  var R = cell.getRow();
  var C = cell.getColumn();
  Browser.msgBox('Row = '+R+' and Col = '+C);
  }

or a more 'universal' function like this :

function getposition(){
   var sh = SpreadsheetApp.getActiveSheet();
   var ss = SpreadsheetApp.getActiveSpreadsheet();
  var range = ss.getActiveRange();
  var R = range.getRowIndex();
  var C = range.getColumnIndex();
  var W = range.getWidth();
  var H = range.getHeight();
  var A1not = range.getA1Notation();
  Browser.msgBox('Row = '+R+' / Col = '+C+' Width = '+W+'  / Heigth = '+H+'  A1 notation = '+A1not);
  }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!