[英]Sheets function working in standalone Google Script but NOT when script is bound to a Google Sheet
I have this piece of code that is working perfectly when I use it in a standalone Google Script running as a web-app :我有这段代码,当我在作为网络应用程序运行的独立 Google 脚本中使用它时,它运行良好:
function getSubjectsRollNosFromGradeSheet() {
var spreadsheetId = '171hWWH8bV6kM1JJ2dvL80q3BoWC6eEc0U7l7wCTaXHE';
var rangeSubject = 'GradesT1!G1:AA1';
var values = Sheets.Spreadsheets.Values.get(spreadsheetId, rangeSubject).values;
However when I write this same code in a Script that is embedded inside another Google sheet (not the one being accessed for data) attached to a Google Form I get an error :但是,当我在附加到 Google 表单的另一个 Google 工作表(不是正在访问数据的工作表)中嵌入的脚本中编写相同的代码时,出现错误:
function updateForm(){
// call your form and connect to the drop-down item
var form = FormApp.openById("1VV_LeFJODZcIzfcYOh8vHEkhl033Lx4ZsXaY4Pm1ZUE");
var subList1 = form.getItemById("497738674").asListItem();
//pull data from another sheet
var spreadSheetID = "1EJSx62rZuLSKIgel7LH8hE7-68lupz4buutmVQBqi2I";
var rangeSubs = 'Sheet1!A1:A';
var subValues = Sheets.Spreadsheets.Values.get(spreadSheetID, rangeSubs).values;
I get this error我收到这个错误
ReferenceError: "Sheets" is not defined.
参考错误:未定义“表格”。 (line 16, file "Code")
(第 16 行,文件“代码”)
Why is the Sheets object available in the first case but not in the second case and how should I change my code to overcome this error.为什么 Sheets 对象在第一种情况下可用,但在第二种情况下不可用,我应该如何更改代码以克服此错误。
Sheets
is one of methods of Advanced Google Services. Sheets
是高级 Google 服务的一种方法。 So in order to use Sheets
of Advanced Google Services, please enable Sheets API for Advanced Google Services and API console as follows.因此,为了使用
Sheets
of Advanced Google Services,请按如下方式启用 Sheets API for Advanced Google Services 和 API 控制台。
Please do this at the bound script which included the script of your question.请在包含问题脚本的绑定脚本中执行此操作。
If I misunderstand your question, I'm sorry.如果我误解了你的问题,我很抱歉。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.