xlsx-cli v1.1.4

This commit is contained in:
SheetJS 2023-10-11 16:22:13 -04:00
parent 53283217e9
commit 432ac1fda7
8 changed files with 65 additions and 19 deletions

2
.gitignore vendored
View File

@ -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]

View File

@ -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;

View File

@ -311,7 +311,7 @@ function parse_cellXfs(t, styles, opts) {
case '<cellXfs': case '<cellXfs>': case '<cellXfs/>': case '</cellXfs>': break;
/* 18.8.45 xf CT_Xf */
case '<xf': case '<xf/>':
case '<xf': case '<xf/>': case '<xf>':
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 '</xf>': break;
/* 18.8.1 alignment CT_CellAlignment */
case '<alignment': case '<alignment/>':
case '<alignment': case '<alignment/>': case '<alignment>':
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 '</alignment>': break;
/* 18.8.33 protection CT_CellProtection */
case '<protection':
case '<protection': case '<protection>':
break;
case '</protection>': case '<protection/>': break;
/* note: sometimes mc:AlternateContent appears bare */
case '<AlternateContent': pass = true; break;
case '<AlternateContent': case '<AlternateContent>': pass = true; break;
case '</AlternateContent>': pass = false; break;
/* 18.2.10 extLst CT_ExtensionList ? */

View File

@ -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 */

View File

@ -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,

View File

@ -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 <https://cdn.sheetjs.com/xlsx-cli/>
### 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`

View File

@ -1,6 +1,6 @@
{
"name": "xlsx-cli",
"version": "1.1.3",
"version": "1.1.4",
"author": "sheetjs",
"description": "Command-line interface for SheetJS",
"keywords": [

7
types/index.d.ts vendored
View File

@ -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;