How can I write the data in Firestore to Google Sheet with app script?

Gu Ki

I have a problem with app script. I try to add my data to Google Sheet but I can't do it. Firstly, I get my data from Firestore. It returns the Document or Document[] variables. So how can I access inside of this variable and write to my Google Sheet? I didn't find anything about for that. Here is my function:

function myFunction(){

  var firestore = FirestoreApp.getFirestore (email, key, projectId);
  const allDocuments = firestore.getDocuments("TEST");

Can you help me please? How can I read that data and write to my Google Sheet?

Renaud Tarnec

The library page provides a link to the wiki, which contains a bit more info.

The getDocuments() method returns an array of the documents in the collection. You just need to loop over this Array and do whatever you want with the documents in this array, e.g. update the Sheet cells.

For example, the following shows one possible approach to get the value of the field1 field for each document:

const allDocuments = firestore.getDocuments("TEST");
for (var i = 0; i < allDocuments.length; i++) {    
    var field1Value = allDocuments[i].fields["field1"];       
    // ...

Based on your update I guess you want to build an array and pass it to appendRow().

The following should do the trick:

  const allDocuments = firestore.getDocuments("TEST");
  var myArray = [];
  for(var i = 0; I < allDocuments.length; i++){
    var chills = allDocuments[i].fields["chills"];

Collected from the Internet

Please contact javaer1[email protected] to delete if infringement.

edited at


Login to comment


How to write data to Google Sheet using PHP

How to write a bound script for a programmatically created google form/sheet

Guarantee mutual exclusion on access and modification of google sheet data in app script

How can I parse an URL's HTML and insert data to a Google Sheet using Google Script?

How can I restore a specific version of my google sheet by using a google script?

How can I assign a Google Sheet script to only one sheet?

How do I get the true range when editing multiple rows on Google Sheet via Google App Script

Can I use Google sheet as data source for my mobile app

How can I search for elements in a parsed XML with Google App Script?

How can i add list of sheets to Google App Script?

How can I tell google script where to print in sheet?

How can I enable "Data Labels" in a Google Sheet via the API?

How can I set Rules in Firebase so that only my app can write on my database firestore?

How can i secure app script from the user who is going to use the google sheet?

Write data from kmz on sheet with Google Apps Script

In Google Sheets how can I write a script to move a drawing to a specific location on the sheet?

How does Google App Script to set a formula to Google sheet cell

Google App Script to Group Row data in sheet based on email column

How can I rearrange a Google Sheet using the data within the sheet?

How can I make a 'google sheet script' or formula to change values in different cells based on a checkbox in the sheet

How do I get arrays mapped in a row in google sheet using JavaScript/Google App script

Using Google Apps Script, how can I replace text in a Google Sheets template to make a new Sheet?

How to refer to other sheet in google app script?

How Can I add comment on a cell using google sheet app script

How can i write systematic data into excel sheet with systematicly?

Split data in google sheet to another sheet using google app script

Not getting exact data from App Script in Google Sheet

App Script Google sheet - button for pasting data values simple form

How do I deploy a simple Google App Script Library to a Google Sheet