简体   繁体   中英

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. However, its pulling data with "StringValue" included in the data as well. 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;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM