为了账号安全,请及时绑定邮箱和手机立即绑定

如何从谷歌表中获取数据作为字典数组

如何从谷歌表中获取数据作为字典数组

白衣非少年 2021-08-26 17:47:39
我很难将行和列中包含的数据格式化为字典数组。以下是我试图实现的格式:[[id: "abchdha", name: "Orange", health: "fruit", price: 50], [id: "123fsf", name: "Apple", health: "fruit", price: 50]]这是我的谷歌表格脚本:var secret = "mysecretcode"function getFirebaseUrl(jsonPath) {  /*  We then make a URL builder  This takes in a path, and  returns a URL that updates the data in that path  */  return (    'myfirebaselink' +    jsonPath +    '.json?auth=' +    secret  )}function syncMasterSheet(excelData) {  /*  We make a PUT (update) request,  and send a JSON payload  More info on the REST API here : https://firebase.google.com/docs/database/rest/start  */  var options = {    method: 'put',    contentType: 'application/json',    payload: JSON.stringify(excelData)  }  var fireBaseUrl = getFirebaseUrl('masterSheet')  /*  We use the UrlFetchApp google scripts module  More info on this here : https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app  */  UrlFetchApp.fetch(fireBaseUrl, options)}function startSync() {  //Get the currently active sheet  var sheet = SpreadsheetApp.getActiveSheet()  //Get the number of rows and columns which contain some content  var [rows, columns] = [sheet.getLastRow(), sheet.getLastColumn()]  //Get the data contained in those rows and columns as a 2 dimensional array  var data = sheet.getRange(1, 1, rows, columns).getValues()  syncMasterSheet(data)}我需要将函数startSync()设置为var data等于我想要的格式。:)
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 179 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信