通过Javascript方法从Google电子表格中获取游标行/列 [英] Getting the cursor row/column from a Google spreadsheet through a Javascript method

查看:110
本文介绍了通过Javascript方法从Google电子表格中获取游标行/列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

2010年3月29日,Jason Hale想用电子表格光标位置为他正在编写的JavaScript应用程序选择一个电子邮件地址 - 请参阅 http://productforums.google.com/forum/#!topic/apps-script/U10q44vptPU 。受访者建议使用getActiveSelection和伴随的getRowIndex / getColumnIndex方法。不幸的是,他们没有为Hale工作,两年后,当我想写一个类似的应用程序时,他们不适合我。游标的位置对getRowIndex和getColumnIndex没有影响。这些方法总是返回1,这是无用的,可能是一个错误。
Google Apps缺少游标服务,例如Python提供的游标服务。有没有人发现任何Google Apps返回的内容在这种情况下可能有用? 下面的代码适用于我。它会在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(您已选择行+ ss.getActiveCell()。getRow());
}


On 29 Mar 2010, Jason Hale wanted to use the spreadsheet cursor location to select an e-mail address for a Javascript app he was writing - See http://productforums.google.com/forum/#!topic/apps-script/U10q44vptPU. Respondents suggested the getActiveSelection and concomitant getRowIndex/getColumnIndex methods. Unfortunately, they didn't work for Hale and they didn't work for me two years later when I wanted to write a similar application. The cursor's location has no effect on getRowIndex and getColumnIndex. These methods always return 1, which is useless and probably a bug. Google Apps lacks a cursor service such as the one Python offers. Has anyone found anything that Google Apps returns that might be useful in this context?

解决方案

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());
}

这篇关于通过Javascript方法从Google电子表格中获取游标行/列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆