Apps脚本:在编辑单元上强制模糊以保存其内容 [英] Apps Script: force blur on editing cell to save its content

查看:69
本文介绍了Apps脚本:在编辑单元上强制模糊以保存其内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的情况:

  • 1个单元格:A1,您可以在其中输入一些文字
  • 1张图像/绘图:单击该脚本会调用一个脚本功能

问题在于该脚本尝试读取A1内容,但是如果您正在编辑它,则其内容不会更新,直到您手动单击另一个单元格为止(因此,如果在编辑A1之后立即在图像上单击该脚本,将读取先前存储的A1值)

The problem is that the script attempts to read A1 content, but if you was editing it, its content is not updated until you manually click in another cell (so if you click directly on the image right after editing A1, the script will read the previously stored A1 value)

问题在于,单击图像不会触发A1上的模糊事件,因此如果您正在编辑内容,则不会存储该内容.我想知道如何使用Apps Script强制模糊/保存/停止编辑单元格,因此我可以确定检索到的值就是您刚刚输入的值.我尝试选择另一个有效范围,但无济于事.

The problem is that clicking in the image doesn't trigger a blur event on A1, so the content is not stored if you was editing it. I would like to know how to force blur / save / stop editing a cell using Apps Script, so I can be sure that the retrieved value is the one that you just entered. I've tried selecting another active range but it doesn't help.

谢谢.

推荐答案

我在Google表格中使用此变通办法,在单击具有相关功能的按钮后,将焦点返回到单元格(我使用程序化打开侧边栏并立即关闭):

I use this workaround, in Google Sheets, to return the focus to a cell after clicking on a button that has a function associated with it (I use the programmatic opening of the sidebar and its immediate closure):

main.gs

function inserisciNuovaRiga() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  sheet.insertRowBefore(2);
  showSidebar();
  var range = sheet.getRange("A2");
  sheet.setActiveRange(range);
}

function showSidebar() {
  var html = HtmlService.createHtmlOutputFromFile('sidebar');
  SpreadsheetApp.getUi().showSidebar(html);
}

sidebar.html

sidebar.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body onload="google.script.host.close();">

  </body>
</html>

您可以在此处找到更多信息(使用翻译,本教程使用意大利语languange):

You can find more info here (use translator, the tutorial is in italian languange):

http://www.appsscript.it/tutorial/google-apps-script-eseguire-una-funzione-al-click- Su-Unbottone在Uno电子表格中的远距镜头聚焦Su-Un-Cella/

以本文的示例为例,在单击按钮之后,代码将插入新行,并将焦点返回到准备编写的第一个单元格中,而只是根据您的需要进行修改.

In the case of the example of the article, after clicking on the button, the code inserts a new line and returns the focus to its first cell ready to write, but simply adapt it to your needs.

这篇关于Apps脚本:在编辑单元上强制模糊以保存其内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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