当应该返回True时,Google脚本比较工作表名称返回False

时间:2018-05-29 19:49:19

标签: javascript google-apps-script

所以我试图让谷歌脚本只能在几张纸上工作。但是,它现在不能正常工作。我尝试记录问题以查看它出错的地方,并且我似乎将完全相同的字符串与其自身进行比较,但是,它返回FALSE。

代码和日志:

function onEdit(e) {

    var activeSheet = e.source.getActiveSheet();
    var activerange = e.range;
  var activeSheetName = activeSheet.getName()
  var ValidRange = {
    top : 3,
    bottom : 200,
    left: 4,
    right: 4,
  };
  var ThisColumn = activerange.getColumn


    Logger.log("active_range: " + activerange);
    Logger.log("active range col: " + activerange.getColumn + "active range row: " + activerange.getRow());
    Logger.log("active_range.value: " + activerange.getCell(1, 1).getValue());
    Logger.log("active_range. colidx: " + activerange.getColumnIndex());
    Logger.log("active sheet: " + activeSheetName);
  Logger.log("RWC Test: " + activeSheetName == "RWC CR's");
  Logger.log("STK Test: " + activeSheetName == "STK CR's");
  Logger.log("Comment Test: " + activeSheetName == "Comment Database");


  if (ThisColumn < activerange.left || ThisColumn > activerange.right) return;
  if (activeSheet.getName() == "RWC CR's" || activeSheet.getName() == "STK CR's" || activeSheet.getName() == "BTWD CR's"){
    var FormulaToUse = range.offset(0, -1).getformula();
   range.SetFormula = FormulaToUse
  };

}



function test_onEdit() {
  onEdit({
    user : Session.getActiveUser().getEmail(),
    source : SpreadsheetApp.getActiveSpreadsheet(),
    range : SpreadsheetApp.getActiveSpreadsheet().getActiveCell(),
    value : SpreadsheetApp.getActiveSpreadsheet().getActiveCell().getValue(),
    authMode : "LIMITED"
  });
}

日志:

[18-05-29 12:44:31:226 PDT] active_range: Range  
[18-05-29 12:44:31:227 PDT] active range col: function getColumn() {/*
*/}  
active range row: 1  
[18-05-29 12:44:31:228 PDT] active_range.value: ID  
[18-05-29 12:44:31:229 PDT] active_range. colidx: 1  
[18-05-29 12:44:31:230 PDT] active sheet: Comment Database  
[18-05-29 12:44:31:230 PDT] false  
[18-05-29 12:44:31:231 PDT] false  
[18-05-29 12:44:31:231 PDT] false  

预期行为:日志中的第3个错误应为True - &#34; Comment Database&#34;是与早期&#34;评论数据库&#34;进行比较的字符串,它应该返回&#34; True&#34;,而不是&#34; False&#34;

请原谅我,如果我犯了某种愚蠢的语言错误,那对谷歌剧本来说相对较新

目标是每当有人输入数据时,它会存储&#34;存储&#34;使用其他地方的公式的数据,使用递归公式重新显示他们输入数据的数据。

1 个答案:

答案 0 :(得分:1)

操作顺序是您的问题

你这样做:

("Comment Test: " + activeSheetName) == "Comment Database"

您正在将字符串添加到变量中,并查看它是否等于其他内容,因此"Comment Test: Comment Database"不等于"Comment Database"

将其更改为

Logger.log("Comment Test: " + (activeSheetName == "Comment Database"))