forked from sheetjs/docs.sheetjs.com
48 lines
1.5 KiB
Bash
Executable File
48 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# https://docs.sheetjs.com/docs/demos/engines/jurassic
|
|
|
|
cd /tmp
|
|
rm -rf SheetJSJurassic
|
|
mkdir SheetJSJurassic
|
|
cd SheetJSJurassic
|
|
|
|
dotnet new console
|
|
dotnet run
|
|
|
|
dotnet add package Jurassic --version 3.2.7
|
|
|
|
curl -LO https://cdn.sheetjs.com/xlsx-0.20.2/package/dist/shim.min.js
|
|
curl -LO https://cdn.sheetjs.com/xlsx-0.20.2/package/dist/xlsx.mini.min.js
|
|
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
|
|
|
|
dotnet run pres.xlsx
|