范围的坐标超出图纸的尺寸。 (但是可以在其他脚本中使用!)

时间:2019-04-10 08:59:59

标签: google-apps-script

此脚本的目的是: -查找与今天的日期匹配的行(Works) -匹配参考号以查找站点(Works) -向某人发送电子邮件,说他们的行已被移动(Works) -进入上述行并发送到相关表格(错误!)

我的以下脚本似乎有些麻烦,我一直在使用Logger.log尝试查找问题,但是它们都给了我我想要的值!但是,脚本不断抛出错误“范围的坐标超出图纸的尺寸。”如果我取出该错误标记的部分,并将其作为独立脚本运行,那么它将起作用!我无法弄清楚为什么附加到此脚本后它不起作用。

function livetestReady() {
    var ss          = SpreadsheetApp.getActiveSpreadsheet();
    var sheet       = ss.getSheetByName("Pending Requests");
    var datarange   = sheet.getDataRange();
    var lastrow     = datarange.getLastRow();
    var values      = datarange.getValues();
    var startRow    = 2;
    var currentDate = new Date();
    var deBug       = "andrew.sallis@rrd.com"
    var valueToSend = ''

    for (var i=lastrow;i>=startRow;i--) {
      Logger.log("Locate")
        var tempDate = values[i-1][4];
        var d = new Date(tempDate);
      Logger.log("d:"+d)
      Logger.log("Today:"+currentDate)
        if(Utilities.formatDate(d, "Europe/London", "EEE, MMM d, yyyy") == Utilities.formatDate(currentDate, "Europe/London", "EEE, MMM d, yyyy"))
          { 
          Logger.log("Now Live: "+i)
          var currentRow  =  values[i-1]
          if(isDate(currentRow[10])) { var corDate = Utilities.formatDate(currentRow[10], "Europe/London", "MMM d, yyyy") } else {var corDate = currentRow[10]}
          var findRef =  currentRow[0]
          var siteRef = "RQT"
          if (Myindexof(findRef,siteRef) > -1) {
              var valueToSend  = "TEW - Requests";
            } else {
              var valueToSend  = "BW - Requests";
          };
          var senderName  =  "CSM Request"
          var replyEmail  =  "Do-Not-Reply@rrd.com"
          var subject     =  "[NOTICE] Your CSM Request '"+values[i-1][0]+"' is now LIVE!.";
          var sendTo      =  currentRow[2]
          var message     =  "<p>A request which you are in control of has now gone live, it can now be found in the '"+valueToSend+"' tab</p>"
          var csmRequest  =  '<p>'
                            +'<table border="1" width="1000" cellspacing="0" cellpadding="10">'
                            +'<tbody>'
                            +'<col width=500>'
                            +'<col width=500>'
                            +'<col width=500>'
                            +'<col width=500>'
                            +'<col width=500>'
                            +'<col width=500>'
                            +'<col width=500>'
                            +'<col width=500>'
                            +'<col width=250>'
                            +'<col width=750>'
                            +'<tr>'
                            +'<td colspan="2" align="center" bgcolor="#CCCCCC"><strong>Reference Number</strong></td>'
                            +'<td colspan="2" align="center" >'+currentRow[0]+'</td>'
                            +'</tr>'
                            +'<tr>'
                            +'<td align="center" bgcolor="#CCCCCC"><strong>Request Expiration Date</strong></td>'
                            +'<td align="center" bgcolor="#CCCCCC"><strong>Requested by</strong></td>'
                            +'<td align="center" bgcolor="#CCCCCC"><strong>Customer</strong></td>'
                            +'<td align="center" bgcolor="#CCCCCC"><strong>File Date</strong></td>'
                            +'</tr>'
                            +'<tr>'
                            +'<td  align="center" >'+Utilities.formatDate(currentRow[6], "Europe/London", "EEE, MMM d, yyyy")+'</td>'
                            +'<td  align="center" >'+currentRow[1]+'</td>'
                            +'<td  align="center" >'+currentRow[8]+'</td>'
                            +'<td  align="center" >'+corDate+'</td>'
                            +'</tr>'
                            +'<tr>'
                            +'<td align="center" bgcolor="#CCCCCC"><strong>Stream ID</strong></td>'
                            +'<td align="center" bgcolor="#CCCCCC"><strong>Batch ID</strong></td>'
                            +'<td align="center" bgcolor="#CCCCCC"><strong>Oracle Number</strong></td>'
                            +'<td align="center" bgcolor="#CCCCCC"><strong>Form Type</strong></td>'
                            +'</tr>'
                            +'<tr>'
                            +'<td align="center" >'+currentRow[11]+'</td>'
                            +'<td align="center" >'+currentRow[12]+'</td>'
                            +'<td align="center" >'+currentRow[14]+'</td>'
                            +'<td align="center" >'+currentRow[15]+'</td>'
                            +'</tr>'
                            +'<tr>'
                            +'<td align="center" bgcolor="#CCCCCC"><strong>Comments</strong></td>'
                            +'<td colspan="3" align="center" >'+currentRow[16]+'</td>'
                            +'</tr>'
                            +'</tbody>'
                            +'</table>'
          var urlToDoc    =    "https://docs.google.com/spreadsheets/d/1ddfQROKL1oROBFEZWrOFpBOZSDpeiRwkaggmUbqV7jg/edit#gid=0"
          var disclaimer  =    "<p>"
                              +"<p>No extra action is required, the hardwork has been done for you!</p>"
                              +"<p><a href='"+urlToDoc+"'>Click here to be taken to the sheet.</a></p>"
                              +"<p>This is an auto-generated email, please do not reply to this.</p>";
          var disclaimer2 =    "<p>"
          var testDisc    =    "<p><strong>This document is currently in a test phase and the information portrayed may not be fully accurate.</strong>.</p>";
          Logger.log("Subject: "+subject)

            MailApp.sendEmail({
            name: senderName,
            replyTo: replyEmail,
            to: sendTo+","+deBug,
            cc: "",
            subject: subject,
            htmlBody: message+csmRequest+disclaimer+testDisc,
            });
          Logger.log("Send to: "+valueToSend)
          Logger.log("Get from: "+sheet.getSheetName())

          var range       = sheet.getRange(i,1,1,17)
          var targetSheet = ss.getSheetByName(valueToSend)
          var targetRow   = targetSheet.getLastRow()+1;
          Logger.log(targetRow)
          targetSheet.getRange(targetRow,1,1,17).setValues(range.getValues());
          range.clearContent()

          var sortLive    = targetSheet.getRange(3,1,targetSheet.getLastRow()-1,targetSheet.getLastColumn())  
          sortLive.sort([{column: 7, ascending:true},{column: 23, ascending:true}])
     }
     var sortPend    = sheet.getRange(3,1,sheet.getLastRow()-1,sheet.getLastColumn())  
     sortPend.sort([{column: 5, ascending:true},{column: 23, ascending:true}])
   }
}

这是导致问题的代码

          Logger.log("Send to: "+valueToSend)
          Logger.log("Get from: "+sheet.getSheetName())

          var range       = sheet.getRange(i,1,1,17)
          var targetSheet = ss.getSheetByName(valueToSend)
          var targetRow   = targetSheet.getLastRow()+1;
          Logger.log(targetRow)
          targetSheet.getRange(targetRow,1,1,17).setValues(range.getValues());
          range.clearContent()
  • Logger.logs显示所需的正确值
  • 值i是正确的行

如果我在没有其余代码的情况下独立运行此部分,那么它将起作用!

我哪里出错了? 预先感谢。

0 个答案:

没有答案