Google apps script “无法运行”;“你好,世界”;谷歌应用程序脚本中的程序。获取有关使用新版Google Sheets的错误消息
我正在阅读Michael Maguire的《Google Sheets Programming with Google Apps Script》一书,并尝试运行以下Hello World类型的函数: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
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服务可以在新旧工作表中使用,那么我只会使用其中一种。您创建了工作表还是从书中复制了模板?