UNPKG

sheetxl

Version:

SheetXL - Command line tool

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