如何使用Google App脚本在Google电子表格中合并多个标签? [英] How can I merge multiple tabs in a Google Spreadsheet using Google App Script?

查看:493
本文介绍了如何使用Google App脚本在Google电子表格中合并多个标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Google App Script合并Google电子表格中的多个标签?例如,我在Google电子表格中有'Sheet1','Sheet2'和'Sheet3'。所有这些表中的数据都有3列 - 名称和电子邮件ID和电子邮件地址。地区。现在,我想将这3张/标签中存在的数据合并/组合成第四张,即具有相同列(姓名,电子邮件地址和地区)的工作表4。第四张纸应该有数据 - Sheet1的数据,然后Sheet2和Sheet3。所有3张中的行数不断变化。

解决方案

  = filter({{Sheet1!A1:C500}; {Sheet2!A1 :C500}; {Sheet3!A1:C500}},{{Sheet1!A1:A500}; {Sheet2!A1:A500}; {Sheet3!A1:A500}}<>)

我没有测试过这个。它只是作为一种可能的解决方案突然出现在我的头上。我不会为此使用脚本;工作表的公式要快得多,至少在大多数时候,YMMV。
请确保使用分号分隔页面部分,否则它将无法工作。分号是数组文字的End_Of_Row运算符。



如果您真的想使用脚本...

  function combineSheets(){
var sApp = SpreadsheetApp.getActiveSpreadsheet();
var s1 = sApp.getSheetByName(Sheet1);
var s2 = sApp.getSheetByName(Sheet2);
var s3 = sApp.getSheetByName(Sheet3);
var s4 = sApp.getSheetByName(Sheet4);
//如果Sheet4不存在,您需要在这里创建它。

var s1values = s1.getRange(1,1,s1.getLastRow(),3).getValues();
var s2values = s2.getRange(1,1,s2.getLastRow(),3).getValues();
var s3values = s3.getRange(1,1,s3.getLastRow(),3).getValues();

//现在,我们可以放在一起并将其填充到Sheet4
var s4values = [];
s4values = s1values.concat(s2values,s3values);
s4.getRange(1,1,s4values.length,3).setValues(s4values);
}


How can I merge multiple tabs in a Google Spreadsheet using Google App Script ? Data in all the tabs keep changing.

For example, I have 'Sheet1', 'Sheet2' and 'Sheet3' in a Google spreadsheet. Data in all these sheets have 3 columns - Name and email ID & Region. Now, I want to merge/combine the data present in these 3 sheets/tabs into a 4th Sheet i.e. 'Sheet 4' having same Columns (name, email Id & Region). The 4th sheet should have data as - data of Sheet1 followed by Sheet2 and then Sheet3. The number of rows in all the 3 sheets keeps changing.

解决方案

= filter({{Sheet1!A1:C500};{Sheet2!A1:C500};{Sheet3!A1:C500}},{{Sheet1!A1:A500};{Sheet2!A1:A500};{Sheet3!A1:A500}}<>"")

I haven't tested this. It just popped into my head as a possible solution. I wouldn't use a script for this; the worksheet formulas are much faster, at least most of the time, YMMV. Make sure you use semicolons to separate the page sections, or it won't work. Semicolons are the End_Of_Row operator for array literals.

If you really want to use a script...

function combineSheets() {
  var sApp = SpreadsheetApp.getActiveSpreadsheet();
  var s1= sApp.getSheetByName("Sheet1");
  var s2= sApp.getSheetByName("Sheet2");
  var s3= sApp.getSheetByName("Sheet3");
  var s4= sApp.getSheetByName("Sheet4");
  //  If Sheet4 doesn't exist you'll need to create it here.

  var s1values = s1.getRange(1,1,s1.getLastRow(),3).getValues();
  var s2values = s2.getRange(1,1,s2.getLastRow(),3).getValues();
  var s3values = s3.getRange(1,1,s3.getLastRow(),3).getValues();

  //  Now, we can put out all together and stuff it in Sheet4
  var s4values = [];
  s4values =  s1values.concat(s2values,s3values);
  s4.getRange(1,1,s4values.length,3).setValues(s4values);
}

这篇关于如何使用Google App脚本在Google电子表格中合并多个标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆