Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json GoogleScripts-如何基于单元格值发送电子邮件_Json_Google Apps Script_Google Sheets_Conditional Formatting - Fatal编程技术网

Json GoogleScripts-如何基于单元格值发送电子邮件

Json GoogleScripts-如何基于单元格值发送电子邮件,json,google-apps-script,google-sheets,conditional-formatting,Json,Google Apps Script,Google Sheets,Conditional Formatting,我是一个谷歌脚本的初学者,我想根据谷歌表单中的单元格值发送电子邮件 确定是否发送电子邮件的单元格位于“FloodEWS”表中的C2 如果该值等于或大于270,我需要发送一封特定的电子邮件。 如果该值等于或大于310,我需要发送另一封电子邮件 到目前为止,我的剧本是: function amberwarning() { // Fetch the combined flow value var combflowrange = SpreadsheetApp.getActiveSpreadshe

我是一个谷歌脚本的初学者,我想根据谷歌表单中的单元格值发送电子邮件

确定是否发送电子邮件的单元格位于“FloodEWS”表中的C2

如果该值等于或大于270,我需要发送一封特定的电子邮件。 如果该值等于或大于310,我需要发送另一封电子邮件

到目前为止,我的剧本是:

function amberwarning() {
  // Fetch the combined flow value
  var combflowrange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("FloodEWS").getRange("C2"); 
  var combflow = combflowrange.getValue();
  // Check combined flow value
  if (270 < combflow < 310){
    // Fetch the email address
    var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Email").getRange("A2");
    var emailAddress = emailRange.getValues();
    
    // Send Alert Email.
    var message = 'It is possible that the Egger site will experience flooding in the coming hours. The advice is to be prepared to take action as combined river flows can increase very quickly during storms. Please keep up to date with the latest river levels for Hexham at <https://flood-warning-information.service.gov.uk/station/9006>. The latest flood warnings from the Environment Agency for Hexham are here <https://flood-warning-information.service.gov.uk/warnings?location=+hexham>. The latest MetOffice weather forecast can be found here <https://www.metoffice.gov.uk/weather/forecast/gcy2xzrne#?>. Please use all available information to inform your decision making. You will keep receiving an email as per each refresh of the latest data. The current combined flow from the North and South Tyne is' + combflow;
    var subject = 'Amber flood warning';
    MailApp.sendEmail(emailAddress, subject, message);
    }
}

非常感谢您的帮助。

假设:

如果该值大于或等于270且小于310,则发送消息1

如果值大于或等于310,则发送消息2

如果还有其他问题,请发送错误消息

根据您的需求修改脚本

使用的纸张:

     A          B         C
---------------------------------
1    RHF        HBF       CF
2    72.25      63.95     311
3       
4    RL         HBL       HL
5    1.566      1.015     32.014

非常感谢你的帮助。我想唯一不是这样的是,如果组合流量<270,我不想收到错误消息,我只是不想发送电子邮件。请使用我的当前代码查看上面编辑的消息
function val() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet8")
var range = sheet.getRange(1, 1, 5, 3);
var data = range.getValues();
var combinedFlow = data[1][2];

var customMsg_1 = "Hey Level 1" ;
var customMsg_2 = "Hey Level 2" ;

if (combinedFlow >= 270 && combinedFlow < 310)
  message = customMsg_1;
  
else if (combinedFlow >= 310)
  message = customMsg_2;
  
else
  message = "error in script";
  
MailApp.sendEmail("user@email.com", "Combined Flow", message);

}