簡體   English   中英

Firestore > Google 表格應用腳本,刪除 StringValue 等

[英]Firestore > Google sheets app script, remove StringValue, etc

我為 Google 表格創建了一個 Appscript,可以根據命令將我的 Firestore 數據庫拉入 Google 表格。 但是,它的拉取數據也包含在數據中的“StringValue”。 我該如何刪除這個? (見截圖) 在此處輸入圖像描述

 function onOpen() { SpreadsheetApp.getUi().createMenu(' Firestore').addItem('Import DB', 'importFromFirestore').addToUi(); } // took my key out for obvious reasons. Replaced with XXXXXXXX - I know its right b/c it pulls the right data function getFirestore() { return FirestoreApp.getFirestore('XXXXXX', 'XXXXXXX', 'XXXXXXXX'); } function importFromFirestore() { // 1. Get a Firestore insance const firestore = getFirestore(); // 2. Get a collection from Firestore const allDocuments = firestore.getDocuments('scores').map(function(document) { return document.fields; }); // 3. Get the first document from the collection const first = allDocuments[0]; const columns = Object.keys(first); const sheet = SpreadsheetApp.getActiveSheet(); sheet.appendRow(columns); // 4. Turn each document into an array to be appended to the sheet allDocuments.forEach(function(document) { const row = columns.map(function(column) { return document[column]; }); sheet.appendRow(row); }); }

在您的代碼更改中:

// 2. Get a collection from Firestore
const allDocuments = firestore.getDocuments('scores').map(function(document) {
return document.fields;
});

// 2. Get a collection from Firestore
const allDocuments = firestore.getDocuments('scores').map(function(document) {
return document.obj;
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM