@sheetxl/io
Version:
IO - Import/Export Libraries for SheetXL.
47 lines (46 loc) • 2.11 kB
JavaScript
import { Workbook as y, IRange as C } from "@sheetxl/sdk";
/**
* @license @sheetxl/io - IO - Import/Export Libraries for SheetXL. - v0.4.0
*
* (C) 2025-present SheetXL Inc. & Michael T. Ford
* License: The license can be found at https://www.sheetxl.com/license.
*/
const k = async (a, p) => {
const { trimLeadingBlankRow: i = !0, trimLeadingBlankColumn: u = !0, excludeHidden: h = !1, sheetKey: r = null, papaParseConfig: m = {} } = p || {}, f = await import("./lYI0OCaOWV2O5ORP.mjs").then((s) => s.p);
if (!a) throw new Error("workbook must be specified");
let t = null;
if (r === null ? t = a.getSelectedSheet() : typeof r == "number" ? t = a.getSheets().search()[r] : typeof r == "string" && (t = a.getSheets().getByName(r)), !t) throw new Error("invalid sheetKey specified");
let c = null;
const d = [];
let e = null, n = t.getUsedRange({ excludeHidden: h });
if (!n) throw new Error("Nothing to export");
if (!i || !u) {
const s = i ? n.getRowStart() : 0, l = u ? n.getColumnStart() : 0;
n = n.getOffsetTo(s, l);
}
n.forEach((s, l) => {
const w = l.getCoords(), x = l.getCell();
c !== w.rowIndex && (e && d.push(e), e = [], c = w.rowIndex);
const S = x.toTextUnformatted() ?? "";
e.push(S);
}, { includeEmpty: !0, address: null }), e && d.push(e);
const o = { ...m }, g = f.unparse(d, o);
return new TextEncoder().encode(g).buffer;
}, R = async (a, p) => {
const { papaParseConfig: i, setValuesOptions: u, constructorOptions: h } = p ?? {}, r = await import("./lYI0OCaOWV2O5ORP.mjs").then((o) => o.p), m = new TextDecoder().decode(a);
let f = -1;
const t = new y(h), c = t.getSelectedSheet().getEntireRange().startIncrementalUpdates({ orientation: C.Orientation.Row }), d = p?.onProgress;
let e = 0;
const n = { ...i, transform: (o, g) => {
i?.transform && (o = i.transform(o, g));
const s = g;
s === 0 && f++;
let l = o ?? "";
return c.pushAt(f, s, l), e++, e % 1e5 == 0 && d?.(e), o;
} };
return r.parse(m, n).data, c.apply({ textParser: !0, ...u }), t;
};
export {
R as fromBufferCSV,
k as toBufferCSV
};