2017年7月12日

用 google app script 在 google 產生 google Form

javascript 語法: https://www.w3schools.com/js/default.asp
google app script: https://developers.google.com/apps-script/guides/sheets/functions
範例來自: http://dsernst.com/2015/07/16/how-to-make-programmatic-google-forms/
從 spreadsheet 抓資料


function getSpreadsheetData(sheetName) {
  // This function gives you an array of objects modeling a worksheet's tabular data, where the first items — column headers — become the property names.
  var arrayOfArrays = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName || 'Sheet1').getDataRange().getValues();
  var headers = arrayOfArrays.shift();
  return arrayOfArrays.map(function (row) {
    return row.reduce(function (memo, value, index) {
      if (value) {
        memo[headers[index]] = value;
      }
      return memo;
    }, {});
  });
}














沒有留言: