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