简体   繁体   English

Google表格-根据输入的值将行推送到第二个电子表格

[英]Google Sheets - Pushing a row to a second spreadsheet based on a value being entered

I'm new to this, 我是新来的

I have 2 google spreadsheets: 我有2个Google电子表格:

Spreadsheet A: The active sheet Containing multiple tabs with information to be Pushed to B. Spreadsheet B: A spreadsheet with a single tab. 电子表格A:活动工作表,包含多个标签,其中包含要推送到B的信息。电子表格B:具有单个标签的电子表格。 The same headers and structure as spreadsheet A. 与电子表格A相同的标题和结构。

Based on the user selecting the answer "Yes" in the first column of any of the 1 tabs in Spreadsheet A, I would like that entire row to move over to Spreadsheet B. 基于用户在电子表格A的1个选项卡的第一页的第一列中选​​择答案“是”,我希望将整行移至电子表格B。

I have modified a script that works on a single spreadsheet (ie moving rows from tab to tab) to attempt to get it to work between spreadsheets: 我修改了一个脚本,该脚本可用于单个电子表格(即,将行从一个标签移动到另一个标签),以尝试使其在电子表格之间工作:

function onEdit(event) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var tss = SpreadsheetApp.openById('B').getSheetByName('Sheet 1');
  var s = event.source.getActiveSheet();
  var r = event.source.getActiveRange();

  if(r.getColumn() == 1 && r.getValue() == "Yes") {
    var row = r.getRow();
    var numColumns = s.getLastColumn();
    var target = tss.getRange(targetSheet.getLastRow() + 1, 1);
    s.getRange(row, 1, 1, numColumns).moveTo(target);
  }
}

Probably needless to say, this yields no result. 也许不用说,这不会产生任何结果。 Having searched through a number of posts and forums I only see individuals posting about how to move rows between tabs but not between entirely separate spreadsheets. 搜索了许多帖子和论坛后,我仅看到个人发布有关如何在选项卡之间而不是在完全独立的电子表格之间移动行的信息。 Is it even possible to do this? 甚至有可能这样做吗? If so, what am I doing wrong in the script? 如果是这样,我在脚本中做错了什么?

Thank you so much for anyone who takes the time to assist. 非常感谢您抽出宝贵时间为您提供帮助。

Anthony 安东尼

Following a dialogue with the OP in the comments section, it was indicated that the original spreadsheet did not to be kept secret. 在与OP的评论部分进行对话之后,指出原始电子表格不应该保密。

Consequently, the desired functionality can be provided by using a combination of IMPORTRANGE() and QUERY() in the spreadsheet with no need to use Google App Script. 因此,可以通过在电子表格中使用IMPORTRANGE()和QUERY()的组合来提供所需的功能,而无需使用Google App脚本。 For instance, 例如,

=QUERY(IMPORTRANGE(url,range),"select A where B matches 'Yes'") or similar

This imports data from a second spreadsheet and then the QUERY() function acts as a way of filtering the imported range by certain criteria. 这将从第二个电子表格中导入数据,然后QUERY()函数充当通过某些条件过滤导入范围的一种方式。

Once the imported range is authorised, the editors of the spreadsheet can access it by, eg removing or modifying the query. 授权导入的范围后,电子表格的编辑者可以通过例如删除或修改查询来访问它。 You could prevent this by protecting that particular cell, if needed. 如果需要,可以通过保护该特定单元格来防止这种情况。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM