deno.land / x / sheetjs@v0.18.3 / demos / vue / native.vue

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
60
61
62
63
64
65
66
67
<!-- xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com --><template> <div class="container"> <image :src="logoUrl" class="logo"></image> <text class="welcome">SheetJS WeeX Demo {{version}}</text> <text class="instructions">Import Data</text> <text :style="{ color: '#841584' }" @click="importFile">Download spreadsheet</text> <text class="instructions">Export Data</text> <text :style="{ color: data.length ? '#841584' : '#CDCDCD', disabled: !data.length }" @click="exportFile">Upload XLSX</text> <text style="instructions">Current Data</text> <scroller class="scroller"> <div class="row" v-for="(row, ridx) in data" :key="ridx"> <text>ROW {{ridx + 1}}</text> <text v-for="(cell, cidx) in row" :key="cidx">CELL {{get_label(ridx, cidx)}}:{{cell}}</text> </div> </scroller> </div></template><style>.container { height: 100%; flex: 1; justify-content: center; align-items: center; background-color: '#F5FCFF'; }.logo { width: 256px; height: 256px; }.welcome { font-size: 40; text-align: 'center'; margin: 10; }.instructions { padding-top: 20px; color:#888; font-size: 24px;}.scroller { height: 500px; border-width: 3px; width: 700px; }.loading { justify-content: center; }</style><script>import XLSX from 'xlsx';const modal = weex.requireModule('modal');const stream = weex.requireModule('stream');export default { data: { data: [[1,2,3],[4,5,6]], logoUrl: 'http://oss.sheetjs.com/assets/img/logo.png', version: XLSX.version, fileUrl: 'http://sheetjs.com/sheetjs.xlsx.b64', binUrl: 'https://hastebin.com/documents' }, methods: { importFile: function (e) { modal.toast({ message: 'getting ' + this.fileUrl, duration: 1 }); var self = this; stream.fetch({method:'GET', type:'text', url:this.fileUrl}, function(res){ const wb = XLSX.read(res.data, {type:'base64'}); const ws = wb.Sheets[wb.SheetNames[0]]; self.data = XLSX.utils.sheet_to_json(ws, {header:1}); }); }, exportFile: function (e) { var self = this; const ws = XLSX.utils.aoa_to_sheet(this.data); const wb = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(wb, ws, "SheetJS"); const wbout = XLSX.write(wb, {type:"base64", bookType:"xlsx"}); const body = wbout; stream.fetch({method:'POST', type:'json', url:this.binUrl, body:body}, function(res) { modal.toast({ message: 'KEY: ' + res.data.key, duration: 10 }); self.version = res.data.key; }); }, get_label: function(r, c) { return XLSX.utils.encode_cell({r:r, c:c})} }}</script>
sheetjs

Version Info

Tagged at
2 years ago