我正在尝试为单元格设置一个值,但它显示错误“未找到范围”。
以下是代码:
function setpush(pushes) {
var sheet2 = SreadsheetApp.getActiveSpreadsheet().getSheetByName("Alerts").getRange(pushes),
pushcell = sheet2.getCell(1,1).setValue("PUSH_SENT");
}
实际上,我正在尝试为Google电子表格创建自定义功能。变量push在代码的最开始声明。
如果错误是由代码结构引起的,以下是完整代码。
// Function that you need to call with valid parameters to check when to notify the user and then if all conditions are met then notify the user
function notify(boolean1, pushes, title, body, url) {
if(boolean1 == "Yes" && pushes != "PUSH_SENT") { //// prevent sending duplicate pushes
sendNotification(pushes, title, body, url);
return "Fired";
} else {
return 'Not Fired';
}
}
/////
// Function that sends notification to an email id
function sendNotification(pushes, title, body, url) {
// Check if edit was made in sendNotificationBoolean, If it was changed then proceed
// Get Range of data that we need to proceed from active sheet
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("basic").getRange('B19'),
// Get email id from range
email = sheet.getCell(1, 1).getValue();
// Run a loop and perform appropriate checks to make sure email id is valid and sendNotification boolean is true/yes
if(email && email.indexOf("@") != -1) {
/* Variable that stores Payload
* email: User email
* type: Type of notification, It can be Note, Link or File. Note suits this.
* body: Body of notification, Any message that you want to send goes here.
* title: Title of notification
*/
var notificationData = {
"email": email,
"type": "link",
"body": body,
"title": title,
"url": url
}
// Important data that has to be sent with every request
// Change access token to change the user from whom notification'll be sent
var options = {
'method': 'post',
'contentType': 'application/json',
'headers': {
'access-token': 'o.13zCbw5nkk9f3VubcJBhZPG2NpCZjTat'
},
'payload': JSON.stringify(notificationData)
};
// Perform a POST request along with options and payload
UrlFetchApp.fetch("https://api.pushbullet.com/v2/pushes", options);
{setpush(pushes)}
}
}
///// Set a value for column N
function setpush(pushes) {
var sheet2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Alerts").getRange(pushes),
pushcell = sheet2.getCell(1,1).setValue("PUSH_SENT");
}
答案 0 :(得分:0)
您似乎正在为getRange()
方法提供单个字符串作为setpush()
函数中的唯一参数。这个单个参数可接受的唯一方法是字符串是A1表示法,例如。 getRange('Alerts!A1:D4')
和/或getRange('D4')
。
要进行问题排查,每次调用Logger.log
时都可以pushes
setpush()
的值,或运行简单的测试函数,如下所示:
function test() {
setpush('A1');
setpush('not A1');
}
预期结果在电子表格的单元格A1中为PUSH_SENT
,然后是您熟悉的未找到范围错误。
有关详细信息,请参阅documentation for getRange()。