首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何将操作单元格更改为在Google Sheets中输入的任何内容

如何将操作单元格更改为在Google Sheets中输入的任何内容
EN

Stack Overflow用户
提问于 2019-02-15 16:37:47
回答 1查看 38关注 0票数 0

我试图让这个脚本运行时,任何文本或日期输入到操作单元格(e.value==“是”)想要更改“是”的任何输入触发脚本。

代码语言:javascript
运行
AI代码解释
复制
function onEdit(e) {
  // see Sheet event objects docs
  // https://developers.google.com/apps-script/guides/triggers/events#google_sheets_events
  var ss = e.source;
  var s = e.range.getSheet();
  var r = e.range;

  // to let you modify where the action and move columns are in the form responses sheet
  var actionCol = 11;
  var nameCol = 8;

  // Get the row and column of the active cell.
  var rowIndex = r.getRowIndex();
  var colIndex = r.getColumnIndex();

  // Get the number of columns in the active sheet.
  // -1 to drop our action/status column
  var colNumber = s.getLastColumn()-3;

  // if our action/status col is changed to ok do stuff
  if (e.value == "yes" && colIndex == actionCol) {
    // get our target sheet name - in this example we are using the priority column
    var targetSheet = s.getRange(rowIndex, nameCol).getValue();
    // if the sheet exists do more stuff
    if (ss.getSheetByName(targetSheet)) { 
      // set our target sheet and target range
      var targetSheet = ss.getSheetByName(targetSheet);
      var targetRange = targetSheet.getRange(targetSheet.getLastRow()+1, 1, 1, colNumber);
      // get our source range/row
      var sourceRange = s.getRange(rowIndex, 1, 1, colNumber);
      // new sheets says: 'Cannot cut from form data. Use copy instead.' 
      sourceRange.copyTo(targetRange);
      // ..but we can still delete the row after
      s.deleteRow(rowIndex);
      // or you might want to keep but note move e.g. r.setValue("moved");
    }
  }
}
EN

回答 1

Stack Overflow用户

发布于 2019-02-17 05:26:57

在……上面

代码语言:javascript
运行
AI代码解释
复制
// if our action/status col is changed to ok do stuff
if (e.value == "yes" && colIndex == actionCol) {

只需删除e.value == "yes" &&

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54713539

复制
相关文章

相似问题

领券
社区富文本编辑器全新改版!诚邀体验~
全新交互,全新视觉,新增快捷键、悬浮工具栏、高亮块等功能并同时优化现有功能,全面提升创作效率和体验
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文