Combining multiple spreadsheets in one using IMPORTRANGE

廉价感情. 提交于 2021-02-17 19:42:23

问题


I would like to aggregate the data of multiple spreadsheets into one spreadsheet.

  • Spreadsheet 1 has a Row of Strings A2:A500
  • Spreadsheet 2 has a Row of Strings A2:A500
  • Spreadsheet 3 is supposed to have a Row of both (Spreadsheet1!A2:A500 AND Spreadsheet2!A2:A500).

Duplicates shall not be handled differently. I would like them to appear as often as they appear in the different sheets.

Is it possible to do this without writing a script or using jQuery, e.g. by using IMPORTRANGE?

What does not work: I have tried using IMPORTRANGE as follows:

ARRAY{IMPORTRANGE("key-of-spreadsheet1","list!A2:A500"), IMPORTRANGE("key-of-spreadsheet2", "list!A2:A500")}

This causes an error.


回答1:


You should be able to use a vertical array in the Spreadsheet 3:

={IMPORTRANGE("Sheet1Key","SheetName!A2:A500");IMPORTRANGE("Sheet2Key","SheetName!A2:A500")}



回答2:


Of course, it is also possible to combine several IMPORTRANGE() functions with the QUERY() function, which gives us a greater control over the results we import.

For example, we can use such a construction:

=QUERY(
  {
    IMPORTRANGE("key-or-url-of-spreadsheet-1", "'sheet-name-1'!A2:Z100");
    IMPORTRANGE("key-or-url-of-spreadsheet-2", "'sheet-name-2'!A2:Z100");
    IMPORTRANGE("key-or-url-of-spreadsheet-3", "'sheet-name-3'!A2:Z100");
    IMPORTRANGE("key-or-url-of-spreadsheet-4", "'sheet-name-4'!A2:Z100")
  },
  "SELECT * WHERE Col1 IS NOT NULL ORDER BY Col3 ASC"
)

Explanation:

The above query removes blank lines from imported ranges:

SELECT * WHERE Col1 IS NOT NULL

and sorts ascending all data collected together in relation to the third column:

ORDER BY Col3 ASC

For descending, just use DESC in place of ASC.

Of course, we can also arrange any other criteria, or omit them displaying everything without modification:

"SELECT * "

Note:

In order to use the above constructed query, we first need to call a single IMPORTIMAGE() method for each of the spreadsheets we want to refer:

=IMPORTRANGE("key-or-url-of-spreadsheet-1", "'sheet-name-1'!A2:Z100")

We have to do this even if we refer to the same spreadsheet in which we write this formula, but for every spreadsheet it is enough to do it once.

This is to be able to connect these sheets and allow access to the sheets (to which we have the access rights anyway):

                                                    

After giving permission for all spreadsheets, we can use the above query.




回答3:


I am also applying above given formula for getting data from multiple spreadsheet which is getting an error something is like IN ARRAY_LITERAL An array literal was missing values for one or more rows.




回答4:


Easy fix: Apply the filter to the entire column / sheet instead of just the current selection. This will automatically update all of the filters to include new additions.



来源:https://stackoverflow.com/questions/31657470/combining-multiple-spreadsheets-in-one-using-importrange

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!