2024-06-15 06:47:40 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
# https://docs.sheetjs.com/docs/demos/engines/jurassic
|
|
|
|
|
|
2026-01-22 06:59:11 +00:00
|
|
|
export DOTNET_CLI_TELEMETRY_OPTOUT=1
|
|
|
|
|
|
2024-06-15 06:47:40 +00:00
|
|
|
cd /tmp
|
|
|
|
|
rm -rf SheetJSJurassic
|
|
|
|
|
mkdir SheetJSJurassic
|
|
|
|
|
cd SheetJSJurassic
|
|
|
|
|
|
|
|
|
|
dotnet new console
|
|
|
|
|
dotnet run
|
|
|
|
|
|
2025-09-04 03:55:16 +00:00
|
|
|
dotnet add package Jurassic --version 3.2.9
|
2024-06-15 06:47:40 +00:00
|
|
|
|
2024-07-18 22:19:02 +00:00
|
|
|
curl -LO https://cdn.sheetjs.com/xlsx-latest/package/dist/shim.min.js
|
|
|
|
|
curl -LO https://cdn.sheetjs.com/xlsx-latest/package/dist/xlsx.mini.min.js
|
2024-06-15 06:47:40 +00:00
|
|
|
curl -LO https://docs.sheetjs.com/pres.xlsx
|
|
|
|
|
|
|
|
|
|
cat >Program.cs <<EOF
|
|
|
|
|
/* sheetjs (C) 2013-present SheetJS -- https://sheetjs.com */
|
|
|
|
|
/* vim: set ts=2: */
|
|
|
|
|
var engine = new Jurassic.ScriptEngine();
|
|
|
|
|
|
|
|
|
|
/* Initialize Jurassic */
|
|
|
|
|
engine.Evaluate("var global = (function(){ return this; }).call(null);");
|
|
|
|
|
|
|
|
|
|
/* Load SheetJS Scripts */
|
|
|
|
|
engine.ExecuteFile("shim.min.js");
|
|
|
|
|
engine.ExecuteFile("xlsx.mini.min.js");
|
|
|
|
|
Console.WriteLine("SheetJS version {0}", engine.Evaluate("XLSX.version"));
|
|
|
|
|
|
|
|
|
|
/* Read and Parse File */
|
|
|
|
|
byte[] filedata = File.ReadAllBytes(args[0]);
|
|
|
|
|
string b64 = System.Convert.ToBase64String(filedata);
|
|
|
|
|
engine.SetGlobalValue("buf", b64);
|
|
|
|
|
engine.Evaluate("var wb = XLSX.read(buf, {type:'base64'});");
|
|
|
|
|
|
|
|
|
|
/* Print CSV of first worksheet*/
|
|
|
|
|
engine.Evaluate("var ws = wb.Sheets[wb.SheetNames[0]];");
|
|
|
|
|
object csv = engine.Evaluate("XLSX.utils.sheet_to_csv(ws)");
|
|
|
|
|
Console.Write(csv);
|
|
|
|
|
|
|
|
|
|
/* Generate XLSB file and save to SheetJSJurassic.ods */
|
|
|
|
|
string ods = engine.Evaluate("XLSX.write(wb, {bookType: 'ods', type: 'base64'})") as string;
|
|
|
|
|
File.WriteAllBytes("SheetJSJurassic.ods", System.Convert.FromBase64String(ods));
|
|
|
|
|
EOF
|
|
|
|
|
|
2026-01-22 06:59:11 +00:00
|
|
|
dotnet run pres.xlsx; echo $?
|
|
|
|
|
npx -y xlsx-cli SheetJSJurassic.ods
|
|
|
|
|
|
|
|
|
|
OS="$(uname -s)"
|
|
|
|
|
ARCH="$(uname -m)"
|
|
|
|
|
|
|
|
|
|
case "$OS" in
|
|
|
|
|
Darwin) OS="osx" ;;
|
|
|
|
|
Linux) OS="linux" ;;
|
|
|
|
|
*) echo "unsupported OS: $OS"; exit 1 ;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
case "$ARCH" in
|
|
|
|
|
x86_64) ARCH="x64" ;;
|
|
|
|
|
arm64|aarch64) ARCH="arm64" ;;
|
|
|
|
|
*) echo "unsupported architecture: $ARCH"; exit 1 ;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
RID="${OS}-${ARCH}"
|
|
|
|
|
|
|
|
|
|
dotnet publish -c Release -r $RID --self-contained true -p:PublishSingleFile=true -p:PublishTrimmed=false
|
|
|
|
|
cp bin/Release/net*/$RID/publish/SheetJSJurassic .
|
|
|
|
|
|
|
|
|
|
rm -f SheetJSJurassic.ods
|
|
|
|
|
./SheetJSJurassic pres.xlsx
|
|
|
|
|
npx -y xlsx-cli SheetJSJurassic.ods
|