待办事项列表 - Google 脚本类型错误:无法在 addTimeStamp(代码:6:25)处读取未定义的属性(读取“源”)

问题描述 投票:0回答:1

待办事项列表任务列表Google 表格/脚本访问链接

  1. function onEdit ---> 不生成日志的问题(无错误)
  2. function 'addTimeStamp' ---> 日志失败的问题返回 Type Error
  3. 我想要的是,当colD(CheckBox=True)中的值时,将setValue(dateTimeStamp)推入每行的ColG

使用 onEdit for checkbox=true (Col D : Row 6) 向下,到右 3 列 (G5) 的偏移量应该返回新的 date() 作为选中行的设置值。这不会返回错误并且执行失败

函数 onEdit 返回,没有任何日志或错误(控制台日志),但“日期时间戳”未在复选框(True)时推送或添加到预期的列 G6、g7、g8 ...等中

函数 addTimeStamp 返回错误“TypeError:无法读取未定义的属性(读取“源”) 在addTimeStamp(代码:6:25)

function onEdit(e) {
  addTimeStamp(e)
}

function addTimeStamp(e) {
  const activeSheet = e.source.getActiveSheet()
  const modifiedCell = e.range
  
  const tf = activeSheet.createTextFinder("Done")             // Find text in sheet for activerange
  tf.matchEntireCell(true)
  const cellDone = tf.findNext()
  const row = cellDone.getRow()
  const col = cellDone.getColumn()

  // console.log(row)
  // console.log(col)

    if(!(modifiedCell.getColumn() === col && modifiedCell.getRow() > row)) return       // guarded statement
    // console.log("I am here")
      console.log(e.value)
    
    if(e.value === "TRUE") {
      modifiedCell.offset(0,3).setValue(new Date())
      console.log(modifiedCell.value)
      console.log(setValue)
    }  

  // SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().createTextFinder().findNext()
  // SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getActiveCell().offset().setValue()
}

google-apps-script google-sheets task
1个回答
0
投票

createTextFinder("Done") 会在找到单元格 D5 之前先找到单元格 A1。

见截图:

将单元格 A1 中的文本更改为其他内容,就像教程中一样。

© www.soinside.com 2019 - 2024. All rights reserved.