Remove need to click before typing when activating a range via a drawing-launched script

六月ゝ 毕业季﹏ 提交于 2019-12-21 17:36:04

问题


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).


回答1:


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.



来源:https://stackoverflow.com/questions/30897408/remove-need-to-click-before-typing-when-activating-a-range-via-a-drawing-launche

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!