/* 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);

/* print CSV rows from first sheet */
console.log(XLSX.utils.sheet_to_csv(wb.Sheets[wb.SheetNames[0]]));

/* 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();
