Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9786

Looping through multiple tabs in multiple sheets, getting values by column names

$
0
0

I am trying to gather data from multiple tabs of different sheets, but a few of my files have the columns in different orders so some of the data is showing up in the "wrong" column (Column C on my master file is Date, but Column C is revenue on one of the files I am grabbing data from). The names of the columns in all files are consistent, just not the order.

This is the code I have so far, but I am not sure how to accommodate the change in column order since for my purposes I can't open every file and rearrange the order manually.

function getDataFromSpreadsheet(ssID){  var ss = SpreadsheetApp.openById(ssID)  var allsheets = ss.getSheets();  var data = []  for(var s in allsheets){    var sheet = allsheets[s];    if(       (sheet.getName() == "Summary") ||        (sheet.getName() == "Data")     )continue;    {      var values = sheet.getRange("A2:G").getValues();      data = data.concat(values)          }  }  return data;}

I also need it to account for the fact that I don't want the headers copied every time, just the data under them (the A2:G range). How can I grab multiple columns by name and assign to an array in the order that I want while still maintaining my for loop?


Viewing all articles
Browse latest Browse all 9786

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>