diff --git a/docz/data/engines.xls b/docz/data/engines.xls index 5c24609..a677787 100644 --- a/docz/data/engines.xls +++ b/docz/data/engines.xls @@ -244,7 +244,7 @@ - +
@@ -297,6 +297,16 @@ + + Duktape + Rust + + + + + + + Duktape Zig diff --git a/docz/docs/03-demos/04-grid/10-tabulator.md b/docz/docs/03-demos/04-grid/10-tabulator.md index d37bbab..9b0fa63 100644 --- a/docz/docs/03-demos/04-grid/10-tabulator.md +++ b/docz/docs/03-demos/04-grid/10-tabulator.md @@ -24,7 +24,7 @@ This demo was tested in the following deployments: | Browser | Version | Date | |:-------------|:--------|:-----------| -| Chromium 125 | `6.2.1` | 2024-06-13 | +| Chromium 133 | `6.3.1` | 2025-03-31 | ::: @@ -45,7 +45,7 @@ installation instructions for projects using a framework. - + ``` ::: @@ -139,7 +139,7 @@ function export_xlsx() { ``` -[The official documentation](https://tabulator.info/docs/6.2/download#xlsx) +[The official documentation](https://tabulator.info/docs/6.3/download#xlsx) covers supported options. #### Post-processing diff --git a/docz/docs/03-demos/42-engines/01-duktape.md b/docz/docs/03-demos/42-engines/01-duktape.md index e0e8649..1ddf130 100644 --- a/docz/docs/03-demos/42-engines/01-duktape.md +++ b/docz/docs/03-demos/42-engines/01-duktape.md @@ -1093,5 +1093,99 @@ sudo cpan install File::Slurp ::: +### Rust + +[`ducc`](https://crates.io/crates/ducc) is a Rust binding to the Duktape engine. +It provides a number of convenience methods for exchanging data with the engine. + +:::note pass + +When this demo was last tested, there were issues passing `Uint8Array` objects +back to Rust. Instead, this demo generates a Base64-encoded string, passes the +string back to Rust, and decodes using the `base64` crate. + +::: + +#### Rust Demo + +:::note Tested Deployments + +This demo was tested in the following deployments: + +| Architecture | Version | Date | +|:-------------|:--------|:-----------| +| `darwin-arm` | `2.2.1` | 2025-03-31 | + +::: + +1) Create a new project: + +```bash +cargo new sheetjs-duk-rs +cd sheetjs-duk-rs +cargo run +``` + +2) Download the SheetJS Standalone script and shim to the `src` folder: + + + +{`\ +curl -L -o src/shim.min.js https://cdn.sheetjs.com/xlsx-${current}/package/dist/shim.min.js +curl -L -o src/xlsx.full.min.js https://cdn.sheetjs.com/xlsx-${current}/package/dist/xlsx.full.min.js`} + + + +3) Download the test file. Move the file to the project directory: + + + + + + + + + +:::caution pass + +If the `curl` command fails, run the commands within WSL `bash`. + +::: + + + + +{`\ +curl -LO https://docs.sheetjs.com/pres.numbers`} + + +4) Download [`main.rs`](pathname:///duk/main.rs) and replace `src/main.rs`: + +```bash +curl -L -o src/main.rs https://docs.sheetjs.com/duk/main.rs +``` + +5) Install dependencies: + +```bash +cargo add ducc base64 +``` + +6) Build and run the app: + +```bash +cargo run pres.numbers +``` + +If the program succeeded, the CSV contents will be printed to console and the +file `sheetjsw.xlsb` will be created. That file can be opened with a spreadsheet +editor that supports XLSB spreadsheets. + + [^1]: See [Foreign Function Interface](https://www.php.net/manual/en/book.ffi.php) in the PHP documentation. [^2]: See [`ctypes`](https://docs.python.org/3/library/ctypes.html) in the Python documentation. \ No newline at end of file diff --git a/docz/static/duk/main.rs b/docz/static/duk/main.rs new file mode 100644 index 0000000..bb2c3c1 --- /dev/null +++ b/docz/static/duk/main.rs @@ -0,0 +1,55 @@ +fn doit(ctx: &ducc::Ducc, code: &str) { ctx.compile(code, None).unwrap().call::<(), ()>(()).unwrap(); } + +fn get_string(str: ducc::Value) -> String { str.as_string().unwrap().to_string().unwrap() } + +fn main() { + let ctx = ducc::Ducc::new(); + + /* initialize */ + doit(&ctx, "var global = (function(){ return this; }).call(null);"); + + /* load library */ + { + doit(&ctx, include_str!("shim.min.js")); + doit(&ctx, include_str!("xlsx.full.min.js")); + } + + /* get version string */ + { + let vers: ducc::Value = ctx.compile("XLSX.version", None).unwrap().call(()).unwrap(); + println!("SheetJS library version {}", get_string(vers)); + } + + /* read file */ + { + let mut iter = std::env::args(); + let path: String = iter.nth(1).expect("must specify a file name"); + + let file: Vec = std::fs::read(path.clone()).unwrap(); + + /* push data to duktape (creates a Uint8Array) */ + let bytes = ctx.create_bytes(file.as_slice()).unwrap(); + + /* assign to global `buf` */ + let _ = ctx.globals().set("buf", bytes); + } + + /* parse workbook */ + { + doit(&ctx, "wb = XLSX.read(buf.slice(0, buf.length), {type:'buffer'});"); + doit(&ctx, "ws = wb.Sheets[wb.SheetNames[0]]"); + } + + /* print CSV */ + { + let csv: ducc::Value = ctx.compile("XLSX.utils.sheet_to_csv(ws)", None).unwrap().call(()).unwrap(); + println!("{}", get_string(csv)); + } + + /* write file */ + { + /* due to issues with the duktape crate, it is easier to pass a base64-encoded string and decode in Rust */ + let xlsb: ducc::Value = ctx.compile("XLSX.write(wb, {type:'base64', bookType:'xlsb'})", None).unwrap().call(()).unwrap(); + let _ = std::fs::write("sheetjsw.xlsb", base64::Engine::decode(&base64::engine::general_purpose::STANDARD, get_string(xlsb)).unwrap()); + } +} diff --git a/docz/static/tabulator/index.html b/docz/static/tabulator/index.html index 432f685..d59cd27 100644 --- a/docz/static/tabulator/index.html +++ b/docz/static/tabulator/index.html @@ -19,7 +19,7 @@ a { text-decoration: none } - +
@@ -32,7 +32,7 @@ a { text-decoration: none }
 
 
 
-
+