最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ReferenceError: "sheet" is not defined - Stack Overflow

programmeradmin1浏览0评论

It is my first time to develop the google script for my google sheet

Here is the code of my script

function doGet(e) {
  var url = ''
  var name = '無標題表單 (回應)'
  var SpreadSheet = SpreadsheetApp.openByUrl(url);   
  var values = sheet.getSheetValues(1, 1, 1, 1);
  Logger.log(values);
}

It is my first time to develop the google script for my google sheet

Here is the code of my script

function doGet(e) {
  var url = 'https://docs.google./spreadsheets/d/1p3fW0Vkx89tdiws3Z-a5_LpLwyGYj7pacIek3f9Z96w/edit#gid=1862590156'
  var name = '無標題表單 (回應)'
  var SpreadSheet = SpreadsheetApp.openByUrl(url);   
  var values = sheet.getSheetValues(1, 1, 1, 1);
  Logger.log(values);
}

When I run the script,and then it show the message "ReferenceError: "sheet" is not defined. (第 7 行,檔案名稱:巨集)"

I try to use the method in this article ReferenceError: "Sheets" is not defined but still cannot work. Thank you!

Share Improve this question asked May 14, 2018 at 9:00 void_serventvoid_servent 11 gold badge1 silver badge1 bronze badge 1
  • 5 add line var sheet = SpreadSheet.getSheetByName('Sheet1'). Define it first, then use. – Max Makhrov Commented May 14, 2018 at 9:03
Add a ment  | 

1 Answer 1

Reset to default 2

tl;dr

Change var SpreadSheet to var sheet in the provided code.


As the error message is explaining: The variable sheet is not defined in the provided code.

This means at the point where sheet is trying to be used, it does not exist yet. It will have to be defined first.

Try running one of the following before you use the variable sheet

var sheet = SpreadSheet.getSheetByName('YourSheetName');

or using .openByUrl

var sheet = SpreadsheetApp.openByUrl(url);
发布评论

评论列表(0)

  1. 暂无评论