Skip to main content

Command-Line Tools

With the availability of JS engines and the success of server-side platforms, it is possible to build standalone command-line tools from JavaScript code.

SheetJS is a JavaScript library for reading and writing data from spreadsheets.

This demo covers a number of strategies for building standalone spreadsheet processors. The ultimate goal is to use SheetJS libraries to generate CSV output from arbitrary spreadsheet files. The generated command-line tool will accept an argument, parse the specified workbook, and print CSV rows to the terminal.

Sample terminal session

$ xlsx-cli.exe pres.numbers
Name,Index
Bill Clinton,42
GeorgeW Bush,43
Barack Obama,44
Donald Trump,45
Joseph Biden,46

Demos for common standalone CLI tools are included in separate pages:

The xlsx-cli NodeJS script is available as a package on the SheetJS CDN. It is an easy-to-use command-line tool for translating files between supported spreadsheet file formats.

For most common deployment scenarios, it is possible to install a server-side platform such as NodeJS.

It is strongly recommended to use a dedicated platform when possible.

The standalone programs generated in this demo are useful when a dedicated server-side scripting platform cannot be installed on the target computer.

NodeJS

There are a few popular tools for compiling NodeJS scripts to CLI programs.

The demo script presents a friendly command line interface including flags:

$ ./xlsx-cli -h
Usage: xlsx-cli [options] <file> [sheetname]

Options:
-V, --version output the version number
-f, --file <file> use specified workbook
-s, --sheet <sheet> print specified sheet (default first sheet)
...
Tested Deployments

This demo was tested in the following deployments:

ArchitectureVersionNodeJSSourceDate
darwin-x644.0.0-rc.414.15.3Pre-built2024-03-15
darwin-arm4.0.0-rc.218.18.0Compiled2023-12-01
win10-x644.0.0-rc.414.15.3Pre-built2024-03-04
win11-arm4.0.0-rc.220.10.0Compiled2023-12-01
linux-x644.0.0-rc.414.15.3Pre-built2024-03-21
linux-arm4.0.0-rc.220.10.0Compiled2023-12-01

0) Download the test file https://sheetjs.com/pres.numbers:

curl -o pres.numbers https://sheetjs.com/pres.numbers

1) Download xlsx-cli.js

curl -o xlsx-cli.js https://docs.sheetjs.com/cli/xlsx-cli.js

2) Install the dependencies:

yarn add https://cdn.sheetjs.com/xlsx-0.20.1/xlsx-0.20.1.tgz exit-on-epipe commander@2

3) Follow tooling steps:

Run nexe and manually specify NodeJS version 14.15.3

npx nexe -t 14.15.3 xlsx-cli.js

This generates xlsx-cli or xlsx-cli.exe depending on platform.

When the demo was tested on ARM targets, the Nexe pre-built packages were missing. The package must be built from source:

npx nexe xlsx-cli.js --build --python=$(which python3) --make="-j8"

On Windows ARM, the target windows-arm64-20.10.0 must be specified:

npx nexe xlsx-cli.js --build --make="-j8" --target=windows-arm64-20.10.0

The Windows build may fail with a vcbuild.bat error:

Error: vcbuild.bat nosign release arm64 exited with code: 1

Pass the -v flag for more details. In the most recent test, the error stemmed from a Python version mismatch:

Node.js configure: found Python 2.7.18
Please use python3.11 or python3.10 or python3.9 or python3.8 or python3.7 or python3.6

The resolved version of Python can be found with

where python

In the most recent test, a Python 2 version appeared first. This was fixed by finding the Python 3 location and prepending it to PATH:

set PATH="C:\correct\path\to\python\three";%PATH%

4) Run the generated program, passing pres.numbers as the argument. For example, nexe generates xlsx-cli in macOS so the command is:

./xlsx-cli pres.numbers

nexe generates xlsx-cli.exe in Windows, so the command is:

.\xlsx-cli.exe pres.numbers

V8

The V8 demo covers standalone programs that embed the V8 engine. This demo uses the Rust integration to generate a command line tool.

Tested Deployments

This demo was last tested in the following deployments:

ArchitectureV8 VersionCrateDate
darwin-x6412.3.219.90.88.02024-03-15
darwin-arm11.8.172.130.79.22023-10-18
win10-x6412.3.219.90.88.02024-03-24
win11-x6411.8.172.130.79.22023-10-14
linux-x6412.3.219.90.88.02024-03-18
linux-arm12.0.267.80.82.02023-12-01

0) Make a new folder for the project:

mkdir sheetjs2csv
cd sheetjs2csv

1) Download the following scripts:

curl -o Cargo.toml https://docs.sheetjs.com/cli/Cargo.toml
curl -o snapshot.rs https://docs.sheetjs.com/cli/snapshot.rs
curl -o sheet2csv.rs https://docs.sheetjs.com/cli/sheet2csv.rs

2) Download the SheetJS Standalone script and move to the project directory:

curl -o xlsx.full.min.js https://cdn.sheetjs.com/xlsx-0.20.1/package/dist/xlsx.full.min.js

3) Build the V8 snapshot:

cargo build --bin snapshot
cargo run --bin snapshot

With some versions of the v8 crate, the Linux AArch64 build failed with an error:

error[E0080]: evaluation of constant value failed

|
1715 | assert!(size_of::<TypeId>() == size_of::<u64>());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: size_of::<TypeId>() == size_of::<u64>()'

Versions 0.75.1 and 0.82.0 are known to work.

4) Build sheet2csv (sheet2csv.exe in Windows):

cargo build --release --bin sheet2csv

5) Download the test file https://sheetjs.com/pres.numbers:

curl -o pres.numbers https://sheetjs.com/pres.numbers

6) Test the application:

mv target/release/sheet2csv .
./sheet2csv pres.numbers

Deno

The exposition has been moved to a separate page.

Dedicated Engines

The following demos for JS engines produce standalone programs: