2026-01-21 06:14:24 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
# https://docs.sheetjs.com/docs/demos/cli/txiki
|
|
|
|
|
cd /tmp
|
|
|
|
|
rm -rf sheetjs-txiki
|
|
|
|
|
mkdir sheetjs-txiki
|
|
|
|
|
cd sheetjs-txiki
|
|
|
|
|
|
|
|
|
|
curl -o pres.numbers https://docs.sheetjs.com/pres.numbers
|
|
|
|
|
|
|
|
|
|
cat >sheet2csv.js <<'EOF'
|
|
|
|
|
const XLSX = require("./xlsx.full.min");
|
|
|
|
|
|
|
|
|
|
/* tjs.args[1] is the first argument to the script */
|
|
|
|
|
const filename = tjs.args[1];
|
|
|
|
|
|
|
|
|
|
/* read and parse file */
|
|
|
|
|
const data = await tjs.readFile(filename);
|
|
|
|
|
const wb = XLSX.read(data);
|
|
|
|
|
|
|
|
|
|
/* generate CSV of first sheet */
|
|
|
|
|
const ws = wb.Sheets[wb.SheetNames[0]];
|
|
|
|
|
const csv = XLSX.utils.sheet_to_csv(ws);
|
|
|
|
|
|
|
|
|
|
/* print to terminal */
|
|
|
|
|
console.log(csv);
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
curl -LO https://cdn.sheetjs.com/xlsx-latest/package/dist/xlsx.full.min.js
|
|
|
|
|
|
2026-01-22 06:59:11 +00:00
|
|
|
OS="$(uname -s)"
|
|
|
|
|
|
|
|
|
|
case "$OS" in
|
|
|
|
|
Darwin)
|
|
|
|
|
curl -LO https://github.com/saghul/txiki.js/releases/download/v24.12.0/txiki-macos.zip
|
|
|
|
|
unzip txiki-macos.zip
|
|
|
|
|
mv txiki-macos/tjs .
|
|
|
|
|
chmod +x tjs
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
Linux)
|
|
|
|
|
echo "Installing txiki.js for Linux"
|
|
|
|
|
git clone --recursive https://github.com/saghul/txiki.js --shallow-submodules
|
|
|
|
|
cd txiki.js
|
|
|
|
|
|
|
|
|
|
make || (
|
|
|
|
|
echo "!!! First build attempt failed, trying with system libffi..."
|
|
|
|
|
rm -rf build
|
|
|
|
|
cmake -B build -DCMAKE_BUILD_TYPE=Release -DUSE_EXTERNAL_FFI=ON
|
|
|
|
|
cmake --build build -j 8
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
cp build/tjs ../
|
|
|
|
|
cd ..
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
*) echo "Unsupported OS: $OS"; exit 1 ;;
|
|
|
|
|
esac
|
2026-01-21 06:14:24 +00:00
|
|
|
|
|
|
|
|
npx -y esbuild sheet2csv.js --bundle --outfile=bundle.js --platform=neutral
|
|
|
|
|
|
|
|
|
|
./tjs compile bundle.js sheet2csv
|
|
|
|
|
./sheet2csv pres.numbers
|