简体   繁体   English

Firestore > Google 表格应用脚本,删除 StringValue 等

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

I got an Appscript created for Google sheets to pull my Firestore database into Google Sheets on command.我为 Google 表格创建了一个 Appscript,可以根据命令将我的 Firestore 数据库拉入 Google 表格。 However, its pulling data with "StringValue" included in the data as well.但是,它的拉取数据也包含在数据中的“StringValue”。 How do I remove this?我该如何删除这个? (see screenshots) (见截图) 在此处输入图像描述

 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); }); }

In your code change:在您的代码更改中:

Before

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

After

// 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