deno.land / x / sheetjs@v0.18.3 / demos / database / FirebaseTest.js

FirebaseTest.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com *//* eslint-env node */const XLSX = require('xlsx');const assert = require('assert');const Firebase = require('firebase-admin');
const config = { credential: { getAccessToken: () => ({ expires_in: 0, access_token: '', }), }, databaseURL: 'ws://localhost:5555'};
/* make new workbook object from CSV */const wb = XLSX.read('a,b,c\n1,2,3', {type:"binary", raw:true});
let P = Promise.resolve("sheetjs");
/* Connect to Firebase server and initialize collection */P = P.then(async () => { Firebase.initializeApp(config); const database = Firebase.database(); await database.ref('foo').set(null); return [database];});
/* Insert entire workbook object into `foo` ref */P = P.then(async ([database]) => { await database.ref('foo').set(wb); return [database];});
/* Change cell A1 of Sheet1 to "J" and change A2 to 5 */P = P.then(async ([database]) => { database.ref('foo').update({ "Sheets/Sheet1/A1": {"t": "s", "v": "J"}, "Sheets/Sheet1/A2": {"t": "n", "v": 5}, }); return [database];});
/* Write to file */P = P.then(async ([database]) => { const val = await database.ref('foo').once('value'); const wb = await val.val(); XLSX.writeFile(wb, "firebase.xlsx"); const ws = XLSX.readFile("firebase.xlsx").Sheets.Sheet1; const csv = XLSX.utils.sheet_to_csv(ws); assert.equal(csv, "J,b,c\n5,2,3\n"); console.log(csv); return [database];});
/* Close connection */P = P.then(async ([database]) => { database.app.delete(); });
sheetjs

Version Info

Tagged at
2 years ago