From 432ac1fda7595b1b7701485ed7824aec602086cd Mon Sep 17 00:00:00 2001 From: SheetJS Date: Wed, 11 Oct 2023 16:22:13 -0400 Subject: [PATCH] xlsx-cli v1.1.4 --- .gitignore | 2 +- bits/27_csfutils.js | 7 +++++ bits/47_styxml.js | 8 +++--- bits/90_utils.js | 8 +++--- bits/95_api.js | 1 + packages/xlsx-cli/README.md | 49 ++++++++++++++++++++++++++++------ packages/xlsx-cli/package.json | 2 +- types/index.d.ts | 7 +++-- 8 files changed, 65 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 0ed4589..dd85dc5 100644 --- a/.gitignore +++ b/.gitignore @@ -23,7 +23,7 @@ tmp *.[xX][mM][lL] *.[xX][lL][mM][lL] *.[uU][oO][sS] -*.[wW][kKqQbB][S1234567890] +*.[wW][kKqQbB][sS1234567890] *.[qQ][pP][wW] *.[fF][mM][3tT] *.[bB][iI][fF][fF][23458] diff --git a/bits/27_csfutils.js b/bits/27_csfutils.js index d8781d8..885f109 100644 --- a/bits/27_csfutils.js +++ b/bits/27_csfutils.js @@ -108,6 +108,13 @@ function sheet_to_workbook(sheet/*:Worksheet*/, opts)/*:Workbook*/ { return { SheetNames: [n], Sheets: sheets }; } +function sheet_new(opts) { + var out = {}; + var o = opts || {}; + if(o.dense) out["!data"] = []; + return out; +} + function sheet_add_aoa(_ws/*:?Worksheet*/, data/*:AOA*/, opts/*:?any*/)/*:Worksheet*/ { var o = opts || {}; var dense = _ws ? (_ws["!data"] != null) : o.dense; diff --git a/bits/47_styxml.js b/bits/47_styxml.js index a5d2a1d..be10ce4 100644 --- a/bits/47_styxml.js +++ b/bits/47_styxml.js @@ -311,7 +311,7 @@ function parse_cellXfs(t, styles, opts) { case '': case '': case '': break; /* 18.8.45 xf CT_Xf */ - case '': + case '': case '': xf = y; delete xf[0]; for(i = 0; i < cellXF_uint.length; ++i) if(xf[cellXF_uint[i]]) @@ -325,7 +325,7 @@ function parse_cellXfs(t, styles, opts) { case '': break; /* 18.8.1 alignment CT_CellAlignment */ - case '': + case '': case '': var alignment = {}; if(y.vertical) alignment.vertical = y.vertical; if(y.horizontal) alignment.horizontal = y.horizontal; @@ -337,12 +337,12 @@ function parse_cellXfs(t, styles, opts) { case '': break; /* 18.8.33 protection CT_CellProtection */ - case '': break; case '': case '': break; /* note: sometimes mc:AlternateContent appears bare */ - case '': pass = true; break; case '': pass = false; break; /* 18.2.10 extLst CT_ExtensionList ? */ diff --git a/bits/90_utils.js b/bits/90_utils.js index 7891f58..231c375 100644 --- a/bits/90_utils.js +++ b/bits/90_utils.js @@ -297,9 +297,11 @@ function wb_sheet_idx(wb/*:Workbook*/, sh/*:number|string*/) { } else throw new Error("Cannot find sheet |" + sh + "|"); } -/* simple blank workbook object */ -function book_new()/*:Workbook*/ { - return { SheetNames: [], Sheets: {} }; +/* simple blank or single-sheet workbook object */ +function book_new(ws/*:?Worksheet*/, wsname/*:?string*/)/*:Workbook*/ { + var wb = { SheetNames: [], Sheets: {} }; + if(ws) book_append_sheet(wb, ws, wsname || "Sheet1"); + return wb; } /* add a worksheet to the end of a given workbook */ diff --git a/bits/95_api.js b/bits/95_api.js index f943e4e..b7b3614 100644 --- a/bits/95_api.js +++ b/bits/95_api.js @@ -9,6 +9,7 @@ var utils/*:any*/ = { decode_cell: decode_cell, decode_range: decode_range, format_cell: format_cell, + sheet_new: sheet_new, sheet_add_aoa: sheet_add_aoa, sheet_add_json: sheet_add_json, sheet_add_dom: sheet_add_dom, diff --git a/packages/xlsx-cli/README.md b/packages/xlsx-cli/README.md index 81e6a7d..380a24a 100644 --- a/packages/xlsx-cli/README.md +++ b/packages/xlsx-cli/README.md @@ -2,19 +2,52 @@ This is a standalone version of the CLI tool for [SheetJS](https://sheetjs.com). -For newer versions of node, the tool should be invoked with `npx`: +The main distribution point is + +### Modern NodeJS + +For newer versions of NodeJS, the tool should be invoked with `npx`: ```bash -$ npx xlsx-cli --help # help and usage info -$ npx xlsx-cli --xlsx test.csv # generates test.csv.xlsx from test.csv +$ npx -p https://cdn.sheetjs.com/xlsx-cli/xlsx-cli-1.1.4.tgz xlsx-cli --help # help and usage info +$ npx -p https://cdn.sheetjs.com/xlsx-cli/xlsx-cli-1.1.4.tgz xlsx-cli test.xlsx # print first worksheet in CSV format +$ npx -p https://cdn.sheetjs.com/xlsx-cli/xlsx-cli-1.1.4.tgz xlsx-cli --xlsx test.csv # generates test.csv.xlsx from test.csv ``` -For older versions of node, the tool should be installed globally: +No install step is required. `npx` will ask to install the module on first run. + +### Legacy NodeJS + +For older versions of NodeJS, the tool should be installed globally: ```bash -$ sudo npm install -g xlsx-cli # install globally (once) - -$ xlsx-cli --help # help and usage info -$ npx xlsx-cli --xlsx test.csv # generates test.csv.xlsx from test.csv +$ npm install -g https://cdn.sheetjs.com/xlsx-cli/xlsx-cli-1.1.4.tgz # install globally (once) ``` +If the global `node_modules` directory is owned by an administrator account, +the install should be run as the `root` user or administrator: + +```bash +$ sudo npm install -g https://cdn.sheetjs.com/xlsx-cli/xlsx-cli-1.1.4.tgz # install globally (once, if root permissions are required) +``` + +The module will configure the `xlsx-cli` command. + +```bash +$ xlsx-cli --help # help and usage info +$ npx xlsx-cli --xlsx test.csv # generates test.csv.xlsx from test.csv +``` + +## Usage + +`xlsx-cli --help` displays full usage information. + +By default, `xlsx-cli path/to/file` will parse the file and print CSV rows from +the first worksheet in the file. + +`xlsx-cli path/to/file ws_name` will use the second argument to determine the +worksheet from which rows are generated + +`xlsx-cli path/to/file --xlsx` will generate a XLSX workbook and save it to a +file whose name is determined by appending `.xlsx` to the name. For example, +`xlsx-cli input.xlsb --xlsx` will save the generated file to `input.xlsb.xlsx` diff --git a/packages/xlsx-cli/package.json b/packages/xlsx-cli/package.json index b624024..37047dd 100644 --- a/packages/xlsx-cli/package.json +++ b/packages/xlsx-cli/package.json @@ -1,6 +1,6 @@ { "name": "xlsx-cli", - "version": "1.1.3", + "version": "1.1.4", "author": "sheetjs", "description": "Command-line interface for SheetJS", "keywords": [ diff --git a/types/index.d.ts b/types/index.d.ts index aabdd4b..25b8d24 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -968,8 +968,11 @@ export interface XLSX$Utils { /* --- General Utilities --- */ - /** Creates a new workbook */ - book_new(): WorkBook; + /** Create a new workbook */ + book_new(ws?: WorkSheet, wsname?: string): WorkBook; + + /** Create a new worksheet */ + sheet_new(opts?: DenseOption): WorkSheet; /** Append a worksheet to a workbook, returns new worksheet name */ book_append_sheet(workbook: WorkBook, worksheet: WorkSheet, name?: string, roll?: boolean): string;