It connects to Firease, collects the documents from a collection and writes them into your google sheet. The script can be copied and pasted as is, just the credentials to Firebase/Firestore needs adding. Blog for more information: https://github.com/grahamearley/FirestoreGoogleAppsScript
const key = '-----BEGIN PRIVATE KEY-----\YourPrivateKeyHere\n-----END PRIVATE KEY-----\n' // TODO - enter your private key here
const email = '[email protected]' // TODO - enter your email here
const projectId = 'YourProjectNameID' // TODO - Enter your project ID here
Clicked Tools > Script Editor Typed up that code. In your case, just paste it! Followed the quick start mentioned here, to install the library, get my secrets and add the secrets to my script https://github.com/grahamearley/FirestoreGoogleAppsScript You’ll see several comments with TODO that you need to fill out Window popped up occasionally asking for permission to connect to my GCP / Firestore instance. I gave it permission Made sure to clicked Save How it works There’s two parts to my script – exports and imports.
Exports: This is largely based on the content of the video but I took it a bit further. Key things I added were:
Column A is the ID of the doc. If it’s blank the document will be added and that field will show the ID from Firestore If it’s not blank it will update the document in Firestore Column H (the far right) I called toDelete. If that field is non-empty it will delete the row in Firestore, then the sheet The video just grabbed 100 rows. My sheet grabs the actual data in the sheet
Imports: I added another menu item and added functionality to:
Import records that don’t exist in the sheet to the sheet Update existing records in the sheet. The import will match up the properties to the correct column Note that it does not handle the situation where the record is not in Firestore but is in the sheet
All the code can be found here, in this repo: https://github.com/bcnzer/firebase-googlesheets-importexport