Google Sheets脚本 - 范围activate()仍然需要用户点击才能输入? [英] Google Sheets script--range activate() still requires user to click in order to type?

查看:173
本文介绍了Google Sheets脚本 - 范围activate()仍然需要用户点击才能输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Google表格撰写简单的脚本。我有一个标签为新条目的按钮(该按钮实际上是一个将脚本分配给它的绘图)。当用户点击按钮时,脚本会在指定位置插入一个空行并激活第一列,以便用户可以开始输入。



一切都很好,除了脚本结束后,用户手动点击表单后,键盘才会工作。正确的细胞被明显激活,但我怀疑焦点仍然(秘密)在图上。这一理论得到如下事实的支持:如果用户点击退出键,他可以根据需要开始在活动单元格中输入内容。

有没有办法自动执行最后一步,以便用户在开始键入之前不需要点击ESC或点击表单?



以下是相关行我正在使用的代码:

  this_sheet.getRange(new_row_num,start_col + 1).activate(); //激活适当的单元格以方便数据输入

我已经尝试了几个其他函数, /或者不是上面显示的代码行,而是总是具有相同的结果。这些其他函数包括 Sheet.activate() Spreadsheet.setActiveSelection(range)

$ b $如果这些函数不按照需要的方式工作,那么获得焦点的解决方法是使用

$ b写入目标单元格
$ b

  this_sheet.getRange(new_row_num,start_col + 1).setValue(); //对于空白单元

,如果它不是一个空白单元格但具有一些现有值,则可以先使用getValue(),然后使用setValue()以保持相同的价值。

I am writing a simple script for a Google Sheet. I have a button labeled "New Entry" (the button is actually a drawing with my script assigned to it). When the user clicks the button, the script inserts an empty row at a specified location and activates the first column so that the user can begin typing.

Everything works great except that after the script finishes, the keyboard doesn't work until after the user manually clicks in the sheet. The correct cell is visibly activated, but I suspect the focus is still (secretly) on the drawing. This theory is supported by the fact that if the user hits the escape key, he can then begin typing in the active cell as desired.

Is there any way to automate this final step so that the user does not need to hit ESC or click into the sheet before begining to type?

Here is the relevant line of code I am using:

this_sheet.getRange(new_row_num, start_col + 1).activate();   // activate the appropriate cell for convenient data entry

I have tried a few other functions in combination with and/or instead of the line of code shown above, but always with the same result. These other functions include Sheet.activate() and Spreadsheet.setActiveSelection(range).

解决方案

If these functions are not working the way as desired, then a workaround to get focus would be to write to the target cell using

this_sheet.getRange(new_row_num, start_col + 1).setValue("");//for blank cell

and if it is not a blank cell but having some existing value then you can use getValue() first and then setValue() so as to keep the same value.

这篇关于Google Sheets脚本 - 范围activate()仍然需要用户点击才能输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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