I need some assistance with extracting data from multiple sheets in a spreadsheet using JavaScript. I have been encountering errors during my attempts, as I am not very familiar with JS. If anyone can provide guidance, it would be greatly appreciated.
function extractData(sheet){
const ss = SpreadsheetApp.getActiveSpreadsheet();
const ws = ss.getSheetByName(sheet);
const data = ws.getRange("A1").getDataRegion().getValues();
const headers = data.shift();
const jsonArray = data.map(row =>{
let obj = {};
headers.forEach((header, index) => {
obj[header] = row[index];
});
return obj;
});
const result = {'sheets': jsonArray};
}
function executeExtraction(){
var sheetNames = ['check1', 'check2', 'check3', 'check4', 'check5'];
for (var i=0; i<sheetNames.length; i++) {
allData = extractData(console.log(sheetNames[i]));
}
return ContentService.createTextOutput(JSON.stringify(allData))
.setMimeType(ContentService.MimeType.JSON);
}
executeExtraction();