简体   繁体   English

谷歌表格应用程序脚本

[英]google sheets apps script

I wanted to ask I have a few lines of code.我想问我有几行代码。 And until yesterday, everything worked perfectly for me.直到昨天,一切对我来说都很完美。

Now when I start debugging the script, it ends up with an error message on line 24 => var ui = SpreadsheetApp.getUi();现在,当我开始调试脚本时,它以第 24 行的错误消息结束 => var ui = SpreadsheetApp.getUi(); . .

Exception: Cannot call SpreadsheetApp.getUi() from this context.异常:无法从此上下文调用 SpreadsheetApp.getUi()。 inputBox @ ulozDataDoDb.gs:24输入框@ulozDataDoDb.gs:24

But when I run this script from the button in the google sheet, it works.但是当我从谷歌表格中的按钮运行这个脚本时,它起作用了。

Does anyone know what to do with it?有谁知道如何处理它?

function inputBox() {
  
  //definice aktivního sešitu
  var ss = SpreadsheetApp.getActive();

  //definice aktivního listu
  var faktura = ss.getSheetByName("faktura");
  var dataBaze = ss.getSheetByName("db");

  //definice promenných pro dalši práci
  var cisloFaktury = faktura.getRange("I3").getValue();
  var varSymbol = faktura.getRange("E22").getValue();
  var datumVystaveni = faktura.getRange("datumVystaveni").getValue();
  var prijmeni = faktura.getRange("prijmeni").getValue();
  var jmeno = faktura.getRange("jmeno").getValue();
  var prijmeniJmeno = jmeno + " " + prijmeni;
  var castka = faktura.getRange("I55").getValue();
  var konstSymb = faktura.getRange("E23").getValue();
  var specSymb = faktura.getRange("E24").getValue();
  var formaUhrady = faktura.getRange("E19").getValue();
  
  //zapsat do DB
  //popis do DB
  var ui = SpreadsheetApp.getUi();
  var popis_v_DB = ui.prompt("Zadejte název do DB.").getResponseText();
  popis_v_DB = popis_v_DB.split(" ").join("_"); //vyhledá mezery a nahradí znakem

The Cannot call SpreadsheetApp.getUi() from this context. Cannot call SpreadsheetApp.getUi() from this context. exception you are receiving is due to the fact that that prompt has to be actioned on by a user and not by a script.您收到的异常是由于该prompt必须由用户而不是脚本来操作。

According to the documentation :根据文档

prompt(prompt) - Will open an input dialog box in the user's editor with the given message and an "OK" button. prompt(prompt) - 将在用户的编辑器中打开一个输入对话框,其中包含给定的消息和一个“确定”按钮。 This method suspends the server-side script while the dialog is open.此方法在对话框打开时暂停服务器端脚本。 The script resumes after the user dismisses the dialog.脚本在用户关闭对话框后恢复。

Reference参考

Try to replace尝试更换

var ui = SpreadsheetApp.getUi();
var popis_v_DB = ui.prompt("Zadejte název do DB.").getResponseText();

by经过

var popis_v_DB = Browser.inputBox("Informace.", "Zadejte název do DB.", Browser.Buttons.OK_CANCEL);

but as far as you ask somebody to enter a value, you will do it by the sheet not by the script editor !但是就您要求某人输入一个值而言,您将通过工作表而不是脚本编辑器来完成!

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

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