UNPKG

sheetxl

Version:

SheetXL - Command line tool

39 lines (38 loc) 1.23 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 o from "node:fs"; import e from "node:path"; const r = async (r2, s) => { const t = r2[0], n = r2[1]; n && console.log("extract range:", n); const l = r2[2]; l && Object.keys(l).length > 0 && console.log("extract options:", l); const c = s.program.opts()?.verbose ?? false, a = s.sdk; c && a.LicenseManager.printBanner(); let i = t; i.endsWith(".xlsx") || (i += ".xlsx"); let p = e.resolve(process.cwd(), i), f = null; o.existsSync(p) || (console.error(`File not found: ${p}`), process.exit(1)); try { f = o.readFileSync(p, { flag: "r" }); } catch (o2) { console.log("Unable to read file:", p), console.error(o2), process.exit(1); } let g = null; try { const o2 = s.io; if (g = await o2.WorkbookIO.read({ source: f.buffer }), c) { const o3 = await g.toJSON(); console.log(`Workbook JSON: ${JSON.stringify(o3, null, 2)}`); } } catch (o2) { console.log(`Unable to parse '${i}' as a workbook`), console.error(o2), process.exit(1); } }; export { r as default };