UNPKG

sheetxl

Version:

SheetXL - Command line tool

57 lines (56 loc) 2.31 kB
/** * @license sheetxl - SheetXL - Command line tool - v0.6.0 * * (C) 2025-present SheetXL Inc. & Michael T. Ford * License: The license can be found at https://www.sheetxl.com/license. */ import { y as e, t } from "../cli.js"; import "node:util"; import "node:path"; import "node:fs"; import "node:os"; import "open"; import "node:repl"; import "chalk"; import "fs"; import "path"; import "commander"; const o = async (e2, t2) => { const { trimLeadingBlankRow: o2 = true, trimLeadingBlankColumn: r2 = true, excludeHidden: n = false, sheetKey: s = null, papaParseConfig: a = {} } = t2 || {}, i = await import("./GxBa1vKUjkoI1-ZZ.js").then((e3) => e3.p); if (!e2) throw new Error("workbook must be specified"); let p = null; if (null === s ? p = e2.getSelectedSheet() : "number" == typeof s ? p = e2.getSheets().getItems()[s] : "string" == typeof s && (p = e2.getSheets().getByName(s)), !p) throw new Error("invalid sheetKey specified"); let l = null; const d = []; let m = null, c = p.getUsedRange({ excludeHidden: n }); if (!c) throw new Error("Nothing to export"); if (!o2 || !r2) { const e3 = o2 ? c.getRowStart() : 0, t3 = r2 ? c.getColumnStart() : 0; c = c.getOffsetTo(e3, t3); } c.forEach((e3, t3) => { const o3 = t3.getCoords(), r3 = t3.getCell(); l !== o3.rowIndex && (m && d.push(m), m = [], l = o3.rowIndex); const n2 = r3.toTextUnformatted() ?? ""; m.push(n2); }, { includeEmpty: true, address: null }), m && d.push(m); const f = { ...a }, u = i.unparse(d, f); return new TextEncoder().encode(u).buffer; }, r = async (o2, r2) => { const { papaParseConfig: n, setValuesOptions: s, createWorkbookOptions: a } = r2 ?? {}, i = await import("./GxBa1vKUjkoI1-ZZ.js").then((e2) => e2.p), p = new TextDecoder().decode(o2); let l = -1; const d = new e(a), m = d.getSelectedSheet().getEntireRange().startIncrementalUpdates({ orientation: t.Orientation.Row }), c = r2?.onProgress; let f = 0; const u = { ...n, transform: (e2, t2) => { n?.transform && (e2 = n.transform(e2, t2)); const o3 = t2; 0 === o3 && l++; let r3 = e2 ?? ""; return m.pushAt(l, o3, r3), f++, f % 1e5 == 0 && c?.(f), e2; } }; return i.parse(p, u).data, m.apply({ textParser: true, ...s }), d; }; export { r as fromBufferCSV, o as toBufferCSV };