问题描述
在电子表格中,我有一个简单的脚本,该脚本添加了新行并将光标移到新行的第二个单元格中:
In my spreadsheet I have a trivial script, which is adding a new row and getting the cursor into the second cell of the new row:
function rowadd() {
var d_akt = SpreadsheetApp.getActive();
var a_akt = d_akt.getActiveSheet();
var w_akt = a_akt.getActiveRange().getRow();
a_akt.insertRowsBefore(w_akt, 1);
a_akt.setActiveRange(a_akt.getRange(w_akt, 2));
}
当用户按下工作表中的按钮时,脚本将运行.几乎可以正常工作,但是在脚本结束后,光标位于正确的单元格中,但是我无法在没有鼠标单击的情况下在该单元格中书写.似乎导航不在工作表中.找不到任何解决该问题的方法.
The script runs when a user presses a button in the sheet. Works almost fine, but after the script ends the cursor is in the right cell, but i cant write in that cell without a mouse click. Looks like the navigation is not in the sheet.Can't find any solution how to fix that issue.
推荐答案
您可以这样创建自己的菜单:
You can create a menu of your own like this:
function onOpen()
{
SpreadsheetApp.getUi().createMenu('My Menu').addItem('Description','functionName').addToUi();
}
我们通常将其放在简单的触发器onOpen()函数中,以便它在您打开文件时运行.您可以在此处了解更多信息.
We typically put it in a simple trigger onOpen() function so that it runs whenever you open the file. You can learn more about it here.
另一个选择是创建一个侧边栏对话框,然后在其中放置按钮.这需要付出更多的努力,但是所付出的代价是,您不必打开下拉菜单.您可以立即单击一个按钮.
Another option is to create a sidebar dialog and put buttons there. That's a little more effort but the pay of is that you don't have to open up a drop down menu. You can just click on a button immediately.
这篇关于脚本添加新行后的导航问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!