forked from SheetJS/sheetjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LocalForage.html
59 lines (55 loc) · 1.38 KB
/
LocalForage.html
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
<!DOCTYPE html>
<!-- xlsx.js (C) 2013-present SheetJS http://sheetjs.com -->
<!-- vim: set ts=2: -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>SheetJS Live Demo</title>
<style>
a { text-decoration: none }
</style>
</head>
<body>
<pre>
<b><a href="http://sheetjs.com">SheetJS LocalStorage Demo</a></b>
<pre id="data_">
Original Data:
</pre>
<pre id="out">
Output:
</pre>
<script src="xlsx.full.min.js"></script>
<script src="ObjUtils.js"></script>
<script src="https://unpkg.com/localforage/dist/localforage.min.js"></script>
<script src="SheetJSForage.js"></script>
<script>
/* eslint-env browser */
/*global XLSX, localforage */
var data = {
"title": "SheetDB",
"metadata": {
"author": "SheetJS",
"code": 7262
},
"data": [
{ "Name": "Barack Obama", "Index": 44 },
{ "Name": "Donald Trump", "Index": 45 },
]
};
document.getElementById("data_").innerText += JSON.stringify(data, 2, 2);
localforage.setDriver(localforage.INDEXEDDB);
(async function() {
await localforage.clear();
await localforage.load(data);
var wb = await localforage.dump();
console.log(wb);
var OUT = document.getElementById("out");
wb.SheetNames.forEach(function(n, i) {
OUT.innerText += "Sheet " + i + " (" + n + ")\n";
OUT.innerText += XLSX.utils.sheet_to_csv(wb.Sheets[n]);
OUT.innerText += "\n";
});
})();
</script>
</body>
</html>