日期搜索自动报告 - Google文档(Date Search for Automatic Reporting - Google Docs)
好的,我在问这个之前已经经过这个站点前进和后退,但由于某种原因我无法获得我已经实现的代码自动工作。 我只需要运行脚本(我已经设置了一个触发器)来检查表5第3列(称为Reports)中的电子邮件。 如果今天的日期与给定的日期相符,我需要它向我发送包含第1列数据和第2列数据的电子邮件。
有人可以查看代码并给我一些帮助吗?
function sendEmails() { var spreadsheet = SpreadsheetApp.openById('Unique ID for spreadsheet'); var sheet = spreadsheet.getSheets()[4]; var startRow = 2; // First row of data to process var numRows = 250; // Number of rows to process // Fetch the range of cells var dataRange = sheet.getRange(startRow, 1, numRows, 4) // Fetch values for each row in the Range. var data = dataRange.getValues(); var emailAddress = 'email@email.com'; var subject = "Report Today"; for (i in data) { var row = data[i]; if( row[3] == true) { var message = row[0]+row[1]; try { MailApp.sendEmail(emailAddress, subject, message); } catch(errorDetails) { MailApp.sendEmail("Email@email.com", "sendEmail script error", errorDetails.message); } } } }
Ok I've been through this site forward and backward before asking this but for some reason I can't get the code I've implemented to work automatically. I just need the script to run (I setup a trigger already) to check the email in column 3 of sheet 5 (called Reports). I need it to send me an email with column 1 data and column 2 data if today's date matches the date given.
Can someone look at the code and give me a little help?
function sendEmails() { var spreadsheet = SpreadsheetApp.openById('Unique ID for spreadsheet'); var sheet = spreadsheet.getSheets()[4]; var startRow = 2; // First row of data to process var numRows = 250; // Number of rows to process // Fetch the range of cells var dataRange = sheet.getRange(startRow, 1, numRows, 4) // Fetch values for each row in the Range. var data = dataRange.getValues(); var emailAddress = 'email@email.com'; var subject = "Report Today"; for (i in data) { var row = data[i]; if( row[3] == true) { var message = row[0]+row[1]; try { MailApp.sendEmail(emailAddress, subject, message); } catch(errorDetails) { MailApp.sendEmail("Email@email.com", "sendEmail script error", errorDetails.message); } } } }
原文:https://stackoverflow.com/questions/28971841
最满意答案
这是可选的展开。
正如你注意到的那样 - 开发者可以将函数的结果转换为MKMarkerAnnotationView
。 但是,if let
语法是可选的解包,他也会使用它。 这意味着这个代码dequeuedView.annotation = annotation view = dequeuedView
只会在投射成功时执行(即投射结果不
nil
)。 否则这段代码将被忽略。你也可以用
guard
语句来做到这一点。 例如:guard let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as? MKMarkerAnnotationView else { // code here will be executed if casting fails. In this case you also have to return function } dequeuedView.annotation = annotation view = dequeuedView
更多信息在文档中
This is optional unwrapping.
As you noticed - developer optionally casted function's result toMKMarkerAnnotationView
. But he also used this withif let
syntax which is optional unwrapping. This means that this codedequeuedView.annotation = annotation view = dequeuedView
will only be executed if cast succeeded (i.e. if cast result wasn't
nil
). Otherwise this code will be ignored.You can also do this with
guard
statement. E.g.:guard let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as? MKMarkerAnnotationView else { // code here will be executed if casting fails. In this case you also have to return function } dequeuedView.annotation = annotation view = dequeuedView
More info in documentation
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
在swift中,如何返回符合协议的相同类型的对象(In swift, how do I return an object of the same type that conforms to a protocol)[2021-12-05]
自动完成功能对您有所帮助,但基本上,如果Foo是一个类,您只需要一个与协议中方法的确切签名相匹配的方法: class Foo {} protocol JSONInitializable { static func initialize(fromJSON: [String : AnyObject]) throws -> Self? } extension Foo: JSONInitializable { static func initialize(fromJSON: [String : ... -
使用Type对象将Object类型的对象转换为另一种类型(Converting an object of the type Object to another type using a Type object)[2022-03-07]
int result = (int)Convert.ChangeType(integerObject, integerType); 当然,在这种情况下,它是一个很无用的练习,但是如果你的“integerObject”的定义不同(字符串也许),那么这是一种行之有效的方法。 您也可能对此问题感兴趣: 使用GetType() int result = (int)Convert.ChangeType(integerObject, integerType); Of course, its a largely us ... -
如何将NSMutableArray转换为特定类型的Swift数组?(How can I cast an NSMutableArray to a Swift array of a specific type?)[2022-01-13]
你可以使这个工作与双重向下,首先是NSArray ,然后到[String] : var strings = myObjcObject.getStrings() as NSArray as [String] 在游乐场测试: import Foundation var objCMutableArray = NSMutableArray(array: ["a", "b", "c"]) var swiftArray = objCMutableArray as NSArray as [String] 更新: 在 ... -
cellForRowAtIndexPath是实际indexPath参数的命名 (或外部)参数,也称为内部参数。 命名参数是您在调用函数时使用的参数。 简而言之,您可以将参数命名为与实际输入变量名称不同的参数。 一个简化的例子 在下面的例子中,我创建了一个带有germanShepherd 命名参数的简单对象: func getDog(barks: Bool, germanShepherd dog: String) {} 然后当我调用我使用的函数时: getDog(true, germanShepherd: ...
-
这是可选的展开。 正如你注意到的那样 - 开发者可以将函数的结果转换为MKMarkerAnnotationView 。 但是, if let语法是可选的解包,他也会使用它。 这意味着这个代码 dequeuedView.annotation = annotation view = dequeuedView 只会在投射成功时执行(即投射结果不nil )。 否则这段代码将被忽略。 你也可以用guard语句来做到这一点。 例如: guard let dequeuedView = mapView.dequeueRe ...
-
PlayingCard(...)不是演员。 这是一个构造函数调用。 如果你想要施放,请使用deck.drawRandomCard() as PlayingCard 。 PlayingCard(...) is not a cast. It's a constructor call. If you want to cast, use deck.drawRandomCard() as PlayingCard.
-
Swift:从接口类型数组转换为Object数组崩溃(Swift: Cast from Interface type array to Object array crashes)[2023-12-07]
听起来像编译器错误,你应该报告它(正如Kevin在评论中所说) 现在,您可以尝试通过单独转换对象来解决它: var someClassObjects : [SomeClass] = myInterfaceObjects.map { $0 as SomeClass } 编辑 :更新到最新的swift语法。 另外值得一提的是这个bug可能已在beta 3或beta 4中得到解决 - 我还没有检查过 Sounds like a compiler bug, you should report it (as Kev ... -
这种方法: JSONSerialization.data(withJSONObject: dictionary, options: .prettyPrinted) 要求dictionary成为“属性列表”。 而这个: [ "weekday" : self.weekday, "available" : self.available, "times" : self.times ] 不是财产清单 ...