【发布时间】:2019-12-31 13:42:04
【问题描述】:
我一直在尝试将数据从 google 电子表格发送到我的 Firestore 数据库(使用此 library),但结果很奇怪。往下看:
我的脚本 - Google Apps 脚本
function firestore() {
// Firestore setup
const email = "xxxxxxxxxx";
const key = "-----BEGIN PRIVATE KEY-----XXXXXXXXXXX-----END PRIVATE KEY-----\n";
const projectId = "xxxxxx";
var firestore = FirestoreApp.getFirestore (email, key, projectId);
// get document data from ther spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheetname = "Orçamento";
var sheet = ss.getSheetByName(sheetname);
// get the last row and column in order to define range
var sheetLR = sheet.getLastRow(); // get the last row
var sheetLC = sheet.getLastColumn(); // get the last column
var dataSR = 2; // the first row of data
// define the data range
var sourceRange = sheet.getRange(2,1,sheetLR-dataSR+1,sheetLC);
// get the data
var sourceData = sourceRange.getValues();
// get the number of length of the object in order to establish a loop value
var sourceLen = sourceData.length;
// Loop through the rows
for (var i=0;i<sourceLen;i++){
var data = [];
data.push({
"id": sourceData[i][0],
"data": sourceData[i][1],
"acao": sourceData[i][2],
"categoria": sourceData[i][3],
"movimentos": sourceData[i][4],
"descricao": sourceData[i][5]
});
firestore.createDocument("orcamento",data);
}
}
这可行,但 Firestore 中的数据有问题。 往下看:
当数据发送到 Firestore 数据库时,它会创建一个“地图”。
怎么了?
谢谢
【问题讨论】:
标签: javascript firebase google-sheets google-cloud-firestore