我很难将行和列中包含的数据格式化为字典数组。以下是我试图实现的格式:[[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等于我想要的格式。:)
添加回答
举报
0/150
提交
取消