Home > Software engineering >  Import multiple Googlesheets into 1 Sheet using AppScript by ID of Folder
Import multiple Googlesheets into 1 Sheet using AppScript by ID of Folder

Time:11-23

I have a script that imports data from different google sheets into one sheet, what do I need to change in the script to seT only ID of the folder where set all my files because I'm trying to import more that 20 files

function getData() {
  get_IDs = ["1pkcy4jx14odSN-Ir2Nqai89_0dJc7RiLapWxRWIURj4", "1J8_cZsjEa9c8vktPBvqGvcdwUBAVkWT3NSdTnXp6tMk"]

  var ss = SpreadsheetApp.getActiveSpreadsheet()
  var copySheet = ss.getSheetByName("Billing card")
  copySheet.getRange('A2:Z').clear()

  let pasteRow = 1

  for (z = 0; z < get_IDs.length; z  ) {
    var ss1 = SpreadsheetApp.openById(get_IDs[z])
    var sheets = ss1.getSheetByName("Billing card")
    var sheetsRange = sheets.getDataRange()
    var sheetsValues = sheetsRange.getValues()

    sheetsValues.splice(0, 5)

    copySheet.getRange(pasteRow 1, 1, sheetsValues.length, sheetsValues[0].length).setValues(sheetsValues)
    pasteRow  = sheetsValues.length
  }

}

CodePudding user response:

Instead of your for loop, you could try something like:

    var files = DriveApp.getFolderById("ReplacewithFolderId").getFiles();
    while (files.hasNext()) {
     var file = files.next();
     var ss1 = SpreadSheetApp.openById(file.getId());
    }

https://developers.google.com/apps-script/reference/drive/drive-app

  • Related