简体   繁体   English

复制包含特定值的行并将其粘贴到另一个工作表

[英]copy rows that contains certain value and paste it to another sheet

I am trying to create a sheet that has a database mastersheet and 8 different locations.我正在尝试创建一个具有数据库主表和 8 个不同位置的工作表。

so everytime I submit a form to the database, I want my code to read the HUB location of the submitted form.所以每次我向数据库提交表单时,我都希望我的代码能够读取提交表单的 HUB 位置。 and copy that details of the submitted form to relevant sheet.并将所提交表格的详细信息复制到相关表格。 this is what I have so far.这就是我到目前为止所拥有的。

basically it will be easier if I describe the flow:基本上,如果我描述流程会更容易:

  1. user enter relevant details用户输入相关详细信息
  2. form submits it to the database sheet表单将其提交到数据库表
  3. code then see which hub it is for then copy the details to the relevant sheet but keeps a copy in the database mastersheet.代码然后查看它用于哪个集线器,然后将详细信息复制到相关工作表,但在数据库主表中保留一份副本。

I hope this makes sense?我希望这是有道理的?

床单

当前代码

from what I can understand you want the answer to the form submitted to the main sheet then once the answer is submitted you what it to be sent to the relevant sheet据我所知,您想要提交给主表格的表格的答案,然后一旦提交答案,您将发送给相关表格的内容

for that i would create a form submit that places the answer to the sheet为此,我将创建一个表单提交,将答案放在工作表中

  const SOURCE_FORM_ID = link; // Change according to your needs

 {
  const form = FormApp.openById(SOURCE_FORM_ID);
  ScriptApp.newTrigger("onFormSubmitTrigger")
    .forForm(form)
    .onFormSubmit()
    .create();
  }



function onFormSubmitTrigger(e) {
  const targetSpreadsheet = SpreadsheetApp.openById("insert sheet id");
  const targetSheet = targetSpreadsheet.getSheetByName("C");
  if (targetSheet.getLastRow() === 0) { // Add headers if they don't exist yet
    const itemTitles = e.source.getItems().map(item => item.getTitle()); // Get item titles
    itemTitles.unshift("Timestamp"); // Append "Timestamp" to the sheet (if desired)
    targetSheet.appendRow(itemTitles); // Append form item titles to the sheet
  }
  const itemResponses = e.response.getItemResponses();
  const responses = itemResponses.map(itemResponse => itemResponse.getResponse()); // Get user responses
  responses.unshift(new Date()); // Add today's date to the responses (if desired)
  targetSheet.appendRow(responses.map(e => Array.isArray(e) ? e.join(",") : e)); // Append responses to the sheet
}

the code above will create a trigger that is linked to your form that will submit the answer to a particular sheet上面的代码将创建一个链接到您的表单的触发器,该触发器将向特定工作表提交答案

after that a on edit or manually triggered code that moves it to the relevant sheet之后,将其移动到相关工作表的编辑或手动触发代码

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var seet = ss.getSheetByName('TC'); //source sheet
  var testrange = seet.getRange('J:J'); //range to check
  var testvalue = (testrange.getValues());
  var csh = ss.getSheetByName('C'); //destination sheet
  var data = [];
  var j =[];

  //Condition check in H:H; If true copy the same row to data array
for (i=0; i<testvalue.length;i++) {
  if ( testvalue[i] == 'SENT') {
  data.push.apply(data,seet.getRange(i+1,1,1,25).getValues());
  //Copy matched ROW numbers to j
  j.push(i);
 }
 }
//Copy data array to destination sheet

 csh.getRange(csh.getLastRow()+1,1,data.length,data[0].length).setValues(data);

//Delete matched rows in the source sheet
  for (i=0;i<j.length;i++){
  var k = j[i]+1;
  sheet.deleteRow(k);

//Alter j to account for deleted rows
  if (!(i == j.length-1)) {
  j[i+1] = j[i+1]-i-1;
}

the code above is what I use to move one row to another sheet with slight bit on modification you can get it to move it to the destination sheet while leaving it in the master sheet if you set up the form submit to send the form data to the master上面的代码是我用来将一行移动到另一张表并稍作修改的代码,如果您设置表单提交以将表单数据发送到大师

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

相关问题 检查JSON响应是否包含特定值 - Check if JSON response contains certain value 查找JSON值是否包含特定文本 - Find if a JSON Value contains certain text 删除JavaScript中包含某些单词的JSON值 - Removing JSON value that contains certain word in JavaScript 如何遍历 CSV 文件并仅将具有特定值的 csv 行写入 JSON 中的另一个文件? - how to iterate through a CSV file and write to another file in JSON only the csv rows with a certain value? 过滤 json 并将其保存到另一个文件,如果它包含 Python 中的某个单词 - Filtering a json and saving it to another file if it contains a certain word in Python 如何查看JSON是否包含某个值,然后进行比较? - How can i see if my JSON contains a certain value and then compare it? 如果此 object 包含具有特定值的密钥,如何在数组中删除 JSON 和 Object? - How to remove in a JSON an Object in an Array if this object contains a key with certain value? 如何循环并检查列表之一是否包含 Python 中的某个值 - How to loop and check if one of the list contains a certain value in Python Select 行,其中嵌套的 JSON 数组包含特定值 - Select row where nested JSON array contains certain value 从包含特定短语的 JSON 解析返回数组值 - Return array value from JSON parse that contains a certain phrase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM