deno.land / x / sheetjs@v0.18.3 / demos / deno / doit.ts

نووسراو ببینە
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
const bts = [ "xlsx", "xlsb", "xls", "csv", "fods", "xlml", "slk"];export default function doit(XLSX: any, tag: string) { const path = "number_format_greek.xls"; let workbook: any;
/* read file */ try { workbook = XLSX.readFile(path); } catch(e) { console.log(e); console.error("Cannot use readFile, falling back to read"); const rawdata = Deno.readFileSync(path); workbook = XLSX.read(rawdata, {type: "buffer"}); }
/* write file */ try { bts.forEach(bt => { console.log(bt); XLSX.writeFile(workbook, `${tag}.${bt}`); }); } catch(e) { console.log(e); console.error("Cannot use writeFile, falling back to write"); bts.forEach(bt => { console.log(bt); const buf = XLSX.write(workbook, {type: "buffer", bookType: bt}); if(typeof buf == "string") { const nbuf = new Uint8Array(buf.length); for(let i = 0; i < buf.length; ++i) nbuf[i] = buf.charCodeAt(i); Deno.writeFileSync(`${tag}.${bt}`, nbuf); } else Deno.writeFileSync(`${tag}.${bt}`, new Uint8Array(buf)); }); }}
sheetjs

Version Info

Tagged at
2 years ago