Skip to content

Instantly share code, notes, and snippets.

Last active Sep 23, 2019
What would you like to do?
Export to Firestore in AppScript
function main() {
var sheet = SpreadsheetApp.getActiveSheet();
// This is set as the collection name
var sheetName = sheet.getName();
var properties = getProperties(sheet);
var records = getData(sheet);
var firestore = getFirestore();
exportToFirestore(firestore, sheetName, records, properties);
// See setup instructions here:
function getFirestore() {
return FirestoreApp.getFirestore('email', 'key', 'projectId');
// Get the first row and its columns - ['author', 'isbn', 'category', 'title']
function getProperties(sheet) {
return sheet.getRange(1, 1, 1, 4).getValues()[0];
// Get the data in the sheet. Starts at row 2, column 1 and then goes down for 100 rows and across 4 columns.
function getData(sheet) {
return sheet.getRange(2, 1, 100, 4).getValues()
sheet.getRange(2, column, numRows, numColumns)
// Save to Firestore.
function exportToFirestore(firestore, collectionName, records, properties) {
var formatBook = createDataFormatter(properties); {
firestore.createDocument(collectionName, book);
function createDataFormatter(properties) {
return function formatter(record, i) {
var data = {};
properties.forEach(function(prop, i) { data[prop] = record[i]; });
return data;
function onOpen() {
SpreadsheetApp.getUi().createMenu('🔥 Firebase').addItem('Export to Firestore', "main").addToUi();
author isbn category title
Sheilah Dignan 099783839-6 Romance Reciprocal
Felice MacTrusty 137337583-3 Thriller Intranet
Carin Corris 831740785-3 Horror Core
Yoko Tancock 971881471-X Horror Contingency
Doralynne Mauger 984730841-1 Science Fiction Solution-Oriented
Flemming Silber 752078866-0 Biography Product
Consuela Cowin 618015156-3 Horror Phased
Sherill Lachaize 605685698-4 Mystery Distributed
Cahra Trengove 307908542-6 Fantasy Context-Sensitive
Randolf Gingles 412593503-3 Fantasy Leverage
Abram Jambrozek 034864179-6 Thriller Well-Modulated
Zondra Weeden 005178721-0 Thriller Horizontal
Maje Lafford 651441865-1 Romance Methodology
Gayleen Biernacki 111684813-9 Drama Proactive
Meghan Scoines 267071122-7 Science Fiction Programmable
Anett Giveen 952220890-6 Horror Bandwidth-Monitored
Fletch Veryard 654452398-4 Biography Executive
Klemens Chalkly 967382989-6 Fantasy Regional
Glenn Albon 798441057-7 Fantasy Interface
Annamaria Celand 092339998-4 Horror Fresh-Thinking
Linell Clayson 130131538-9 Romance Mandatory
Darill Janas 517298977-3 Fantasy Time-Frame
Micheal Nisard 641272279-3 Mystery Pre-Emptive
Matti Grimsdell 819404951-2 Horror User-Facing
Aube Lefort 656260727-2 Biography Encompassing
Sandi Manser 178689552-8 Romance Instruction Set
Jaimie Bloodworth 861065532-6 Science Fiction Challenge
Ario Hacaud 405052425-2 Drama Bifurcated
Franky Stavers 896131528-5 Thriller Neural-Net
Liv Kristof 322405649-5 Romance Enhanced
Kylynn Lafrentz 158457877-7 Science Fiction Web-Enabled
Minnie Eagleston 682231126-2 Romance Conglomeration
Bordie Gives 806936675-3 Science Fiction Access
Elene Crame 371430581-5 Fantasy Universal
Imelda Dewerson 338562266-2 Biography Switchable
Deeann Bowering 604463940-1 Science Fiction Networked
Yovonnda Rollingson 757268358-4 Mystery Firmware
Nick Ivanusyev 231672748-4 Biography Public-Key
Latrina Mortimer 105787216-4 Thriller Holistic
Kass Devinn 768712995-4 Thriller Middleware
Kelsy Lytton 279248107-2 Mystery Middleware
Rich Akester 509773827-6 Science Fiction Standardization
Billy Hrus 208550369-1 Thriller Open Architecture
Arthur Bartak 774703761-9 Memoir Multi-Lateral
Leeanne Duffie 488451841-1 Biography Local
Ceil Shevlane 800322839-5 Drama Ergonomic
Lenna Shankle 866539380-3 Memoir Bifurcated
Lidia Birtley 103240444-2 Drama Intangible
Walton Lamport 845487386-4 Biography Context-Sensitive
Clareta Durnin 336154252-9 Romance Tertiary
Klement Baack 251716919-5 Romance Front-Line
Cristabel Tunnock 084876596-6 Science Fiction Actuating
Stinky Henrie 435834342-2 Thriller Protocol
Gabbie Nicholes 222924623-2 Romance Attitude
Marlo Gritsaev 729578207-9 Mystery Demand-Driven
Gray Gilhouley 334814231-8 Memoir Website
Viki Huygen 418970467-9 Science Fiction Disintermediate
Barbaraanne Oxby 858786285-5 Biography Dynamic
Mariska Phillis 897393859-2 Horror Down-Sized
Kristoffer Muress 683480893-0 Memoir Alliance
Kaja Kingsman 945073005-9 Horror Mandatory
Dinnie Sapir 578918611-4 Thriller Disintermediate
Liesa Cutress 009993512-0 Thriller Encoding
Cathlene Faircliffe 859501967-3 Horror Synergy
Corny Skingley 301698778-3 Memoir Cross-Group
Fionna Puddle 080560373-5 Romance Re-Contextualized
Dave Akenhead 299136948-5 Thriller Optimizing
Fedora Batstone 040652327-4 Memoir Object-Oriented
Marcelle Papaminas 826368497-8 Fantasy Synergistic
Christin Kaser 897444644-8 Memoir Solution
Agnese Millis 122540899-7 Fantasy Help-Desk
Gwyneth McLucky 904813184-7 Science Fiction Synergy
Torrence Coggell 035988806-2 Fantasy Complexity
Ray Planke 261539778-8 Biography Upgradable
Dino Rosengren 613479119-9 Biography Coherent
Anselma Tutill 041489529-0 Memoir Process Improvement
Margret Red 028605796-4 Biography Synchronised
Artair Chater 905836982-X Biography Conglomeration
Ferd Leah 506521468-9 Thriller Monitoring
Lutero Capstake 100296282-X Drama Budgetary Management
Ashil Buttriss 138641971-0 Thriller Empowering
Darrell Runge 295881124-7 Fantasy Tangible
Cammy Morden 168504780-7 Thriller Versatile
Almeria Berrycloth 425644460-2 Horror Virtual
Skelly Sammon 574973302-5 Thriller Software
Hewe Dibdin 148197716-4 Science Fiction Upgradable
Dario Morrison 069847190-3 Science Fiction Capability
Wiatt Kivits 962859964-X Horror Client-Server
Pattie Dingate 450232745-X Biography Innovative
Ketti Sandeland 847976241-1 Horror Neutral
Pietra Heinreich 197245014-X Biography Phased
Klarika Ferroni 784745758-X Thriller Orchestration
Fairfax Beeson 171140396-2 Science Fiction Content-Based
Brandi Boatwright 621542476-5 Drama Moderator
Alfie Vennard 981899640-2 Thriller Customizable
Felisha Dollman 757169984-3 Drama Secondary
Dav Fleote 299824018-6 Memoir Multi-Lateral
Nalani Hiers 890908849-4 Horror Methodical
Travers Holyard 745507920-6 Thriller Needs-Based
Christina McHale 446905141-1 Romance Exuding
Copy link

yushdotkapoor commented Sep 23, 2019

I can't seem to use custom document names from the spreadsheet! What can I do? I've been working on this for a week and cannot figure it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment