function myFunction() {
var data = getDataOfSheetId('xxxxx-xxxxxxxxxxxxxxxxxxxx_xxxxxx', 0);
console.log(data);
}
function getDataOfSheetId(spreadsheetId, sheetIndex) {
var book = SpreadsheetApp.openById(spreadsheetId);
var sheet = book.getSheets()[sheetIndex];
console.log(sheet.getName());
var [rows, columns] = [sheet.getLastRow(), sheet.getLastColumn()];
var data = sheet.getRange(1, 1, rows, columns).getValues();
var header = data[0];
data.shift();
return data.map(function(row) {
return header.reduce(function(o, h, i) {
o[h] = row[i];
return o;
}, {});
});
}
参考:
javascript - How to get data from google sheets as an array of dictionary - Stack Overflow
コメント