简体   繁体   English

在Google Apps脚本上提示用户输入,使用getUi()方法出错

[英]Prompt user input on Google Apps Script, error with `getUi()` method

I have been trying to write a script to display a prompt box that will take in user input for me to use to open a website. 我一直试图编写一个脚本来显示一个提示框,该框将吸收用户输入,供我用来打开网站。

I am trying the following code 我正在尝试以下代码

var ui = SpreadsheetApp.getUi();
var response = ui.prompt('Please input email address', ui.ButtonSet.YES_NO);

But i get an error message saying 但是我收到一条错误消息说

"The api method 'getUi' is not available yet in the new version of Google Sheets." “ api方法'getUi'在新版Google表格中尚不可用。”

Does any know how I can work around this so that I can get the user input. 有谁知道如何解决此问题,以便获得用户输入。 I have searched everywhere for a solution but couldn't find any way to get user input. 我到处都在寻找解决方案,但找不到任何方法来获取用户输入。

Thank you. 谢谢。

I had the same problem. 我有同样的问题。 This error occurred for me when I tried to use the getUI() method in a google spreadsheet that was created prior to the "New" google spreadsheets. 当我尝试在“新” google电子表格之前创建的Google电子表格中使用getUI()方法时,发生了此错误。 I don't know if the old sheets have been migrated yet to the new sheets, but in any event simply creating a new spreadsheet and copying my data across did the trick. 我不知道旧工作表是否已迁移到新工作表,但是无论如何,只要创建一个新的电子表格并复制我的数据就可以了。

When I use your code in an onOpen() function of the New Google Spreadsheet, it's working for me without an error: 当我在新的Google Spreadsheet的onOpen()函数中使用您的代码时,它对我有用,没有错误:

function onOpen() {

  var ui = SpreadsheetApp.getUi();
  var response = ui.prompt('Please input email address', ui.ButtonSet.YES_NO);

}

That above code works for me. 上面的代码对我有用。 It automatically shows a prompt when the sheet is opened or refreshed. 打开或刷新工作表时,它会自动显示提示。 So, we need more info to isolate the problem. 因此,我们需要更多信息来隔离问题。 Do you want the function to run when the Sheet opens, or is the code being triggered in some other way? 您是要在工作表打开时运行该函数,还是要以其他方式触发代码?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM