简体   繁体   English

使用数组公式连接两个独立的工作表

[英]Use array formulas to concatenate two independent sheets

I have two Google Sheets with identical layouts that are filled in by independent teams: 我有两个布局完全相同的Google表格,由独立的团队填写:

Sheet 1: 表格1:

team1_entry1 243
team1_entry2 546
etc
...
XXX

Sheet 2: 表格2:

team2_entry1 166
team2_entry2 888
...
XXX

I need to see the data from both sheets in one table, which I can then filter and sort using Filter Views. 我需要在一个表中查看两个工作表中的数据,然后可以使用“过滤器视图”进行过滤和排序。 I wrote a simple Apps Script function to go through each sheet and grab all the values until it hits "XXX". 我编写了一个简单的Apps脚本函数,以遍历每个工作表并获取所有值,直到达到“ XXX”为止。 The collected data is then written as a two-dimensional array in my sheet. 然后,将收集到的数据作为二维数组写入我的图纸中。 (I use IMPORTRANGE() of this data into another sheet, from which I generate my Filter Views, etc.) (我将此数据的IMPORTRANGE()放入另一张工作表中,从中生成过滤器视图等。)

The problem 问题

This workflow doesn't work offline (Apps Script needs the internet to run), and I would like to be able to work on this data when I don't have internet access. 该工作流程无法离线运行(Apps Script需要运行互联网),并且我希望能够在无法访问Internet时处理这些数据。

Would it be possible to do this kind of sheet data concatenation using some kind of array formula wizardry? 是否可以使用某种数组公式向导来进行这种工作表数据连接?


My currently-working script code, for reference: 我当前正在工作的脚本代码,以供参考:

function CreateMasterTableTest( ) { 
  var name_of_a_sheet                  = 'Team1Sheet';
  var name_of_b_sheet                  = 'Team2Sheet';
  var num_tables                       = 2;
  var database_terminating_string      = 'XXX';
  var start_of_data_row_index          = 1; // 2nd row in the sheet
  var ss                               = SpreadsheetApp.getActiveSpreadsheet();

  var all_values    = [];
  var a_sheet       = ss.getSheetByName( name_of_a_sheet );
  var range         = a_sheet.getDataRange();
  all_values[ 0 ] = range.getValues();  
  var b_sheet       = ss.getSheetByName( name_of_b_sheet );
  var range         = b_sheet.getDataRange();
  all_values[ 1 ]   = range.getValues();
  var output_array                     = [];
  var global_row_index                 = 0;
  var end_of_data_encountered          = false;

  ////////////////////////////////////////////////////////////////////
  // Now I have to reserve space for the second dimension
  ////////////////////////////////////////////////////////////////////
  for ( var i = 0; i < ( all_values[ 0 ].length + all_values[ 1 ].length ); i++ ) {    
     output_array[ i ] = output_array[ i ] || []; 
  }

  ////////////////////////////////////////////////////////////////////
  // Walk through each row and each column of each sheet
  ////////////////////////////////////////////////////////////////////
  var a_num_rows = all_values[ 0 ].length;
  var a_num_cols = all_values[ 0 ][ 0 ].length; // this gets the number of cols   
  for ( var table_index= 0; table_index < num_tables; table_index++ ) {    
   for ( var row = 0; row < a_num_rows; row++ ) {
    for ( var col = 0; col < a_num_cols; col++ ) { 
      temp_val                        = String( all_values[ table_index ][ row ][ col ] ); //#VALUE! 
      ///////////////////////////////////////////////////////////////////////////
      // At this point we shall check for the terminating string
      ///////////////////////////////////////////////////////////////////////////
      if ( database_terminating_string == temp_val ) {
          end_of_data_encountered = true;          
          break; 
      }            
      if ( start_of_data_row_index <= row ) {
          output_array[ row - start_of_data_row_index + global_row_index ][ col ] = temp_val; 
      }      
    }    
    if (  end_of_data_encountered == true ) {
      end_of_data_encountered = false;
      global_row_index = row - 1;
      break;
    } //end of if
   } // end of row for loop
  } // end of tables for loop
  return output_array;
}

Edit 2: Here is the sheet formula I have come up with, but I can't get it to work for both sheets: 编辑2:这是我想出的工作表公式,但我无法使它适用于两个工作表:

=Indirect( "Sheet1!A3:HA" & Match( "XXX", Sheet1!A3:A1000, 0 ) + 1 )

And likewise for Sheet2 对于Sheet2同样

=Indirect( "Sheet2!A3:HA" & Match( "XXX", Sheet2!A3:A1000, 0 ) + 1 )

Below doesn't work for me: 以下不适用于我:

=concat( Indirect( "Sheet1!A3:HA" & Match( "XXX", Sheet1!A3:A1000, 0 ) + 1 ), Indirect( "Sheet2!A3:HA" & Match( "XXX", Sheet2!A3:A1000, 0 ) + 1 ) )

I need something similar to concat that works for Arrays, perhaps. 我可能需要与concat类似的东西,也许适用于Arrays。

Edit3: Seem to have found a solution Edit3:似乎已找到解决方案

Instead of concat above, use {array1;array2} approach. 代替上面的concat,使用{array1; array2}方法。

In other words, in my case it is: 换句话说,在我的情况下是:

={Indirect( "Sheet1!A3:HA" & Match( "XXX", Sheet1!A3:A1000, 0 ) + 1 ); = {Indirect(“ Sheet1!A3:HA”&Match(“ XXX”,Sheet1!A3:A1000,0)+ 1); Indirect( "Sheet2!A3:HA" & Match( "XXX", Sheet2!A3:A1000, 0 ) + 1 ) } 间接(“ Sheet2!A3:HA”和Match(“ XXX”,Sheet2!A3:A1000,0)+ 1)}

={Indirect( "Sheet1!A3:HA" & Match( "XXX", Sheet1!A3:A1000, 0 ) + 1 ); Indirect( "Sheet2!A3:HA" & Match( "XXX", Sheet2!A3:A1000, 0 ) + 1 ) }

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

相关问题 基于两列条件的 Google 表格中的排名和数组公式 - Rank and Array Formulas In Google Sheets based on criteria from two columns 如何在 Google 表格的一个单元格中使用两个公式? - How do I use two formulas in one cell on Google Sheets? 在Google表格中连接两个范围 - Concatenate two ranges in Google Sheets 如何在谷歌表格中组合嵌套数组公式? - How to combine nested array formulas in google sheets? 在谷歌表格中创建一个表格以与表格公式一起使用 - Creating a table in google sheets for use with table formulas Google表格串联一系列IF - Google Sheets Concatenate an Array of IFs 我正在尝试将 6 列合并为两列,我无法使用连接,Google 表格不断更新行 - I am trying to combine 6 columns into two, I cant use concatenate, Google Sheets is constantly updating the rows 串联Google表格脚本中的两列 - Concatenate two columns in google sheets script Google 表格中的数组公式、连接和 If Function - Array Formula, Concatenate, and If Function in Google Sheets Google Form to Google Sheets - 如何不断将表单数据发送到两个不同的独立工作表以进行独立编辑(不是镜像) - Google Form to Google Sheets - How to constantly send form data to two different independent sheets for independent editing (Not a mirror)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM