Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script “无法运行”;“你好,世界”;谷歌应用程序脚本中的程序。获取有关使用新版Google Sheets的错误消息_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script “无法运行”;“你好,世界”;谷歌应用程序脚本中的程序。获取有关使用新版Google Sheets的错误消息

Google apps script “无法运行”;“你好,世界”;谷歌应用程序脚本中的程序。获取有关使用新版Google Sheets的错误消息,google-apps-script,google-sheets,Google Apps Script,Google Sheets,我正在阅读Michael Maguire的《Google Sheets Programming with Google Apps Script》一书,并尝试运行以下Hello World类型的函数: function sayHelloAlert() { // Declare a string literal variable. var greeting = 'Hello world!', ui = SpreadsheetApp.getUi(); // Display a mess

我正在阅读Michael Maguire的《Google Sheets Programming with Google Apps Script》一书,并尝试运行以下Hello World类型的函数:

function sayHelloAlert() {
  // Declare a string literal variable.
  var greeting = 'Hello world!',
  ui = SpreadsheetApp.getUi();
  // Display a message dialog with the greeting
  //(visible from the containing spreadsheet).
  // Older versions of Sheets used Browser.msgBox()
  ui.alert(greeting);
}

当我选择这个函数并尝试运行它时,它返回一个错误:
api方法“getUi”仅在新版googlesheets中可用。(第3行,文件“代码”)。我怎么能不使用新版Google Sheets?在过去的一周里,我才刚刚开始使用谷歌脚本。如何验证我使用的是哪个版本?

您必须在工作表中创建一个新的电子表格,然后从“工作表”菜单转到“工具-->脚本编辑器”。您无法直接访问scripts.google.com。

对于电子表格的使用,我将使用
浏览器
类:

如果电子表格只供您使用,那么只要您使用新的工作表,使用
.getUi()
就没有问题。但是,如果其他用户正在运行代码,并且正在使用旧的工作表,他们将得到一个错误


在电子表格类中,我没有看到使用代码获取用户Google表单版本的任何方法。我不知道高级驱动器服务在文件的元数据中是否包含该信息。但是,如果浏览器类或HTML服务可以在新旧工作表中使用,那么我只会使用其中一种。

您创建了工作表还是从书中复制了模板?