简体   繁体   English

Google Script:根据值将行从一张纸复制到另一张纸

[英]Google Script: Copy row from one sheet to another depending on value

While ive seen similar questions ive not seen this specific one if im not mistaken.如果我没记错的话,虽然我见过类似的问题,但我没有见过这个具体的问题。

So, i need to read all the info in a certain column (in this case it would be AF, regardless i havent been using that spreadsheet to try what ive been doing out) and then check whether a cell in that column has the value(or string, sorry new to Google Script) "Finalized" then copy the entire row that corresponds to that cell to a secondary sheet which would store all the finished cases and stuff.所以,我需要阅读特定列中的所有信息(在这种情况下,它将是 AF,无论我是否一直在使用该电子表格来尝试我一直在做的事情),然后检查该列中的单元格是否具有值(或字符串,对不起,Google Script 的新手)“完成”,然后将与该单元格对应的整行复制到辅助工作表,该辅助工作表将存储所有已完成的案例和内容。

ive been trying to find something thru google but its always how to copy the entire sheet and thats not useful i think, also what ive done rn copies the cells regardless of what the value is on that cell+column我一直试图通过谷歌找到一些东西,但它总是如何复制整个工作表,我认为这没有用,而且我所做的 rn 复制单元格,无论该单元格 + 列上的值是什么

function copyIf() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var source = ss.getSheetByName("Stuff"); 
  var destination = ss.getSheetByName("Terminados");
  var condition = source.getRange('D2:D2000').getValue();
  if (condition == "Terminado") {  
    source.getRange('A2').copyTo(destination.getRange('A2'));
    source.getRange('A3').copyTo(destination.getRange('A3'));
  } 
}

i am thinking i should probably implement some sort of for or while loop cause i want this to run constantly so whenever someone changes the status of a certain cell to Terminado to copy that row to the secondary sheet.我在想我可能应该实施某种 for 或 while 循环,因为我希望它不断运行,所以每当有人将某个单元格的状态更改为 Terminado 以将该行复制到辅助工作表时。

Try this尝试这个

function copyIf() {
  var feuille = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Stuff");
  var archive = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Terminados");
  if (feuille.getLastRow()==1){
    SpreadsheetApp.getActive().toast('No data!', 'End of script 🗃️')
    return
  }
  var data = feuille.getRange(2,1,feuille.getLastRow()-1,feuille.getLastColumn()).getValues()
  var archiveData = []
  var lignes = []
  var ligne = 1
  var col = 31 // AF
  try {
    data.forEach(function (row) {
      if (row[col]=="Terminado") {
        archiveData.push(row)
        lignes.push(ligne)
      }
    })
    archive.getRange(archive.getLastRow() + 1, 1, archiveData.length, archiveData[0].length).setValues(archiveData)
    // lignes.reverse().forEach(x => feuille.deleteRow(x));
    SpreadsheetApp.getActive().toast('Rows '+lignes.flat()+' hab been archived !', 'End of script 🗃️')
  } catch (e) {
    SpreadsheetApp.getActive().toast('No data to be archived!', 'End of script 🗃️')
  }
}

If you want to delete rows after process, remove // before lignes.reverse().forEach(x => feuille.deleteRow(x));如果要在处理后删除行,请在lignes.reverse().forEach(x => feuille.deleteRow(x));之前删除//

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google电子表格将值从一行复制到另一张工作表 - Google spreadsheet copy values from one row to another sheet 将一行从一个Google表格电子表格复制到表单提交中的另一表格 - Copy a row from one Google Sheet Spreadsheet to Another on Form Submit 将数据从一张纸复制到另一张 - Google Script - Copy Data from one sheet to another - Google Script google脚本:根据触发将公式计算出的值从一张纸复制到另一张纸上(在编辑或时间驱动下) - google script: To copy the value calculated by formula from one sheet to another based on TRIGGER (on edit or time driven) 根据单元格值将行从一张纸复制到另一张纸 - Copy row from one sheet to another base on cell value 如何使用 Google Sheet Script 将数据范围从一个工作表复制到另一个工作表 - How to Copy a data range from one sheet to another sheet using Google Sheet Script Google 工作表脚本将数据集从一张工作表复制到另一张工作表的顶部(仅限值) - Google sheets script copy data sets from one sheet to another (values only) at the top of the sheet Google 工作表应用程序脚本 - 根据循环条件将数据从一张工作表复制到另一张工作表 - Google sheet app script - Copy data from one sheet to another based on condition with loop 谷歌脚本将数据从工作表 1 复制到第一个空行工作表 2 - google script copy data from sheet 1 to first empty row sheet 2 Google脚本的实现,用于将行从一张纸移动到另一张纸 - Implementation of Google script for Moving row from one sheet to another sheet Implementation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM