docs.sheetjs.com/docz/static/quickjs/SheetJSQuick.js

29 lines
713 B
JavaScript
Raw Normal View History

2023-03-12 06:25:57 +00:00
/* sheetjs (C) 2013-present SheetJS -- https://sheetjs.com */
/* load XLSX */
import * as std from "std";
globalThis.global = globalThis;
std.loadScript("xlsx.full.min.js");
/* read contents of file */
var rh = std.open("pres.numbers", "rb");
rh.seek(0, std.SEEK_END);
var sz = rh.tell();
var ab = new ArrayBuffer(sz);
rh.seek();
rh.read(ab, 0, sz);
rh.close();
/* parse file */
var wb = XLSX.read(ab);
2023-12-05 03:46:54 +00:00
/* print CSV rows from first sheet */
console.log(XLSX.utils.sheet_to_csv(wb.Sheets[wb.SheetNames[0]]));
2023-03-12 06:25:57 +00:00
/* write XLSX */
var out = XLSX.write(wb, {bookType: "xlsx", type: "array"});
/* write contents to file */
var wh = std.open("SheetJSQuick.xlsx", "wb");
wh.write(out, 0, out.byteLength);
wh.close();