Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
Combining Two Functions that Build Two Separate Arrays

I've been working on this script for two weeks now and can't figure it out. I think I need to combine these two functions to create one array and use the getSheetNames() function to be more of a descriptor. Then I want to run a separate function to filter the array into two different sheets on a master document based on sheet name. Any help would be greatly appreciated.

//Function to pull all data from workbook
function getDataFromSpreadsheet1(ssID) {
  
  //Open workbook
  let ss = SpreadsheetApp.openById(ssID);
  //Get all sheets in workbook and put into array
  let data = ss.getSheets().map(sh => sh.getRange(4, 1, sh.getLastRow() - 2, 3).getValues()).flat(1);
  Logger.log(data);
  return data;
  
}

//Function to return name of sheets in workbook
function getSheetNames(ssID) {

  let ss = SpreadsheetApp.openById(ssID);
  let sheets = ss.getSheets();
  let session = [];
  sheets.forEach(function (sheet) { 
    session.push(sheet.getName());
  });
  Logger.log(session);
  return session;

}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Combining multiple Sheets of multiple spreadsheets

function getDataFromSpreadsheet1(ssID) {
  const ssids = ['ssID1', 'ssID2'];
  data = []
  ssids.forEach(ssid => {
    let ss = SpreadsheetApp.openById(ssid);
    let vs = ss.getSheets().map(sh => sh.getRange(4, 1, sh.getLastRow() - 2, 3).getValues()).flat(1);
    data.push(vs)
  })
  Logger.log(data);
  return data;
}

flat()

array

about 4 years ago · Juan Pablo Isaza Report

0

Here's what you need.

function getDataFromSpreadsheet1(ssID) {

  //Open workbook
  let ss = SpreadsheetApp.openById(ssID);
  //Get all sheets in workbook and put into array
  let data = ss.getSheets().map(sh =>{
        return [[sh.getName()],sh.getRange(4, 1, 3, 3).getValues().flat(1)]
  });

  console.log(data);
  return data;

}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!