Code Monkey home page Code Monkey logo

export-data-from-cloud-firestore-to-google-sheets's Introduction

Hi there ๐Ÿ‘‹

NishaniKasineshan

  • ๐Ÿ‘‹ Iโ€™m Nishani
  • ๐Ÿ‘€ Iโ€™m interested in Image Processing, Computer Vision, Machine Learning and Deep Learning
  • ๐ŸŒฑ Iโ€™m currently learning Computer Engineering at University Of Peradeniya
  • ๐Ÿ’ž๏ธ Iโ€™m looking to collaborate on Computer Vision,machine learning and deeplearning projects
  • โšก Fun fact: I love taking power naps ๐Ÿ˜ด
  • ๐Ÿ“ซ How to reach me through my mail- [email protected]

Connect with me:

nishani-kasineshan-1b6890189 15821025 TryHackMe


Nishani's github stats

export-data-from-cloud-firestore-to-google-sheets's People

Contributors

nishanikasineshan avatar

Stargazers

 avatar

Watchers

 avatar

export-data-from-cloud-firestore-to-google-sheets's Issues

How to also Update after creation?

Hello, can you write a code on how to also Update after creation?

Here's mine below.

`function onOpen() {
SpreadsheetApp.getUi().createMenu('๐Ÿ”ฅ Firebase')
.addItem('โช Export to Firestore', 'main')
.addItem('โฉ Import from Firestore', 'menuImport')
.addToUi();
}

function main() {
var email = "fireb...ccount.com";
var key = "-----BEGI...rxEp...RIVATE KEY-----\n";
var projectId = "co...t";

var sheet = SpreadsheetApp.getActiveSheet();

var sheetName = sheet.getName();

var properties = getProperties(sheet);

var records = getRecords(sheet);

var firestore = FirestoreApp.getFirestore(email, key, projectId);
updateFirestoreDocument(firestore, sheetName, documentId, properties, data);
exportToFirestore(firestore, sheetName, properties, records);

}

function updateFirestoreDocument(firestore, collectionName, documentId, properties, data) {
var documentRef = firestore.getDocument(collectionName, documentId);
if (documentRef.exists()) {
properties.forEach(function(prop) {
documentRef.updateData(prop, data[prop]);
});
} else {
firestore.createDocument(collectionName, documentId, data);
}
}

function exportToFirestore(firestore, collectionName, properties, records) {
records.map(function(record) {
var data = {};
properties.forEach(function(prop,i) { data[prop] = record[i]; });
if (data[properties[0]] === undefined || data[properties[0]] === null) {
return;
}
// var documentId = data[properties[1]]; // first column
firestore.createDocument(collectionName, data);
// firestore.createDocument(collectionName, documentId, data, { id: documentId });
});
}

function getProperties(sheet){
return sheet.getRange(2, 1, 1, sheet.getLastColumn()).getValues()[0];
}

function getRecords(sheet) {
var data = sheet.getDataRange().getValues();
var dataToImport = [];
for (var i = 2; i < data.length; i++) {
dataToImport.push(data[i]);
}
return dataToImport;
}`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.