【问题标题】:Combine multiple sheet into one master sheetCombine multiple sheet into one master sheet
【发布时间】:2022-12-02 07:47:00
【问题描述】:

I have a separate google sheet with data on 3 separate tabs with the same columns. I want to dynamically have that data go to a master sheet on another google sheet. I have this script below but the issue is it creates a new sheet and i want it to constantly update the existing sheet. I can;t ise import range because the data is too large.

I think i will use a time trigger daily

function concatAllSheets()
{
  var includedSheet=['Not_Completed','Complete','Declined'];
  var ss=SpreadsheetApp.openById("sheet code");
  var ts=SpreadsheetApp.getActive();
  var allSheets=ss.getSheets();
  var sheetName='Master'
  var mother=ts.appendSheet(sheetName);
  for(var i=0;i<allSheets.length;i++)
  {
    var sht=allSheets[i];
    if(includedSheet.indexOf(sht.getName())>-1)
    {
      var rng=sht.getDataRange();
      var rngA=rng.getValues();
      for(var j=0;j<rngA.length;j++)
      {
        var row=rngA[j];
        mother.appendRow(row);
      }
    }
  }
}

【问题讨论】:

    标签: google-apps-script google-sheets


    【解决方案1】:

    Try this:

    function concatAllSheets() {
      const incl = ['Sheet0', 'Sheet1', 'Sheet2'];//included sheets you will need to edit them
      const dss = SpreadsheetApp.openById(gobj.globals.testsourceid);//You will need to edit the destination id for the spreadsheet where master sheet is
      const osh = dss.getSheetByName("Master");
      osh.clearContents();
      const sss = SpreadsheetApp.getActive();
      const arr = sss.getSheets().filter(sh => ~incl.indexOf(sh.getName())).map(sh => sh.getDataRange().getValues());
      arr.forEach(a => osh.getRange(osh.getLastRow() + 1, 1, a.length,a[0].length).setValues(a));
    }
    

    This includes the header rows

    【讨论】:

      猜你喜欢
      • 2022-12-27
      • 1970-01-01
      • 2023-01-06
      • 2023-01-22
      • 2014-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-18
      相关资源
      最近更新 更多