I’m trying to merge the data from all the sheets into one sheet. How can I escape the [] inside the query function?
function listAllProducts() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheets = spreadsheet.getSheets();
// Start from index 1 to skip the first sheet
for (var i = sheets.length - 1; i > 1; i--) {
QUERY({sheets[i]!A2:Z},"select * where Col1 is not null");
}
}
Google Sheets – Google App Script
I was expecting the names of each sheet to automatically be populated to the query so I manually don’t have to type each query. Each sheet varies in length and size and there are numerous sheets. Perhaps there is a better way to do this? Any help would be appreciated, Thank you!
2
Answers
Iterate over the sheets starting with an index of 1 and get the data range from the active sheet.
Note: you can not call the Google Sheet function QUERY from Google App Script. If you provide more context maybe we can provide a solution for the final step.
List all sheet contents in an array of 2d arrays with labels on top row of each sheet data array