我遇到了这段代码的问题。谷歌不赞成使用的几件作品。现在,在制作新工作表并尝试使用旧代码时,我会收到错误,无法通过google上的文档找到更改方法。
function doGet(e) {
//This is not working?
if (typeof e.parameter.id == 'undefined'){
return no_id(e) // The URL doesn't have an ?id=345 on the end!
}
var id = parseInt( e.parameter.id ) // This is the id of the row in the spreadsheet.
//Script properties is changed and I think it is now: PropertyService.getScriptProperties() // Get the data from the spreadsheet and get the row that matches the id
var this_spreadsheet_id = ScriptProperties.getProperty('this_spreadsheet_id')
var ss = SpreadsheetApp.openById(this_spreadsheet_id)
var sheet = ss.getSheetByName("Sheet1")
var range = sheet.getDataRange()
var last_row = range.getLastRow()
var last_column = range.getLastColumn()
for(i = 2; i <= last_row ; i++){
var this_row = sheet.getRange(i,1 , 1, last_column)
var values = this_row.getValues()[0]
var row_id = parseInt( values[0] )
//row id == id is not working either
if ( row_id == id){
var title = values[5]
var details = values[8]
var status_txt = values[7]
Logger.log( "STATUS: " + status )
var image_url = values[4]
}
}
}
任何想法都会很棒!
谢谢,
答案 0 :(得分:0)
&#34; ReferenceError:&#34; id&#34;没有定义。 (第23行,文件&#34;代码&#34;)&#34;
在定义id之前,您在if语句中返回。因此,如果未定义,则触发if语句。将变量定义移到顶部。
var id = parseInt( e.parameter.id ) // This is the id of the row in the spreadsheet.
//Script properties is changed and I think it is now: PropertyService.getScriptProperties() // Get the data from the spreadsheet and get the row that matches the id
var this_spreadsheet_id = ScriptProperties.getProperty('this_spreadsheet_id')
var ss = SpreadsheetApp.openById(this_spreadsheet_id)
var sheet = ss.getSheetByName("Sheet1")
var range = sheet.getDataRange()
var last_row = range.getLastRow()
var last_column = range.getLastColumn()
if (typeof e.parameter.id == 'undefined'){
return no_id(e) // The URL doesn't have an ?id=345 on the end!
}