This commit is contained in:
SheetJS 2023-10-26 21:49:35 -04:00
parent cf283192e1
commit 36d350427c
9 changed files with 111 additions and 70 deletions

View File

@ -21,8 +21,8 @@ Each standalone release script is available at <https://cdn.sheetjs.com/>.
When referencing by file name, AMD loaders typically omit the file extension.
The actual file name is `xlsx.full.min.js`, but the examples will refer to the
script as `xlsx.full.min`.
The actual file name is `xlsx.full.min.js`, but the examples identify the script
using the name `xlsx.full.min`
:::

View File

@ -29,7 +29,7 @@ This demo was tested in the following environments:
| Environment | AlaSQL | Date |
|:--------------------|:-------|:----------:|
| NodeJS | 3.1.0 | 2023-07-24 |
| NodeJS | 3.1.0 | 2023-10-26 |
| Standalone (Chrome) | 3.0.0 | 2023-08-20 |
:::

View File

@ -119,7 +119,7 @@ This demo was tested in the following deployments:
| Architecture | Version | Date |
|:-------------|:--------|:-----------|
| `darwin-x64` | `2.7.0` | 2023-07-24 |
| `darwin-x64` | `2.7.0` | 2023-10-26 |
| `darwin-arm` | `2.7.0` | 2023-10-18 |
| `win10-x64` | `2.7.0` | 2023-07-24 |
| `win11-arm` | `2.7.0` | 2023-09-26 |
@ -293,23 +293,40 @@ may not work on every platform.
### Perl
The Perl binding for Duktape is available on CPAN:
The Perl binding for Duktape is available as `JavaScript::Duktape` on CPAN.
The Perl binding does not have raw `Buffer` ops, so Base64 strings are used.
#### Perl Demo
:::note
This demo was tested in the following deployments:
| Architecture | Version | Date |
|:-------------|:--------|:-----------|
| `darwin-x64` | `2.5.0` | 2023-10-26 |
:::
0) Ensure `perl` and `cpan` are installed and available on the system path.
1) Install the `JavaScript::Duktape` library:
```bash
cpan install JavaScript::Duktape
```
The Perl binding does not have raw `Buffer` ops, so Base64 strings are used.
With the [ExtendScript](/docs/getting-started/installation/extendscript) build:
2) Save the following codeblock to `SheetJSDuk.pl`:
```perl SheetJSDuk.pl
```perl title="SheetJSDuk.pl"
# usage: perl SheetJSDuk.pl path/to/file
use JavaScript::Duktape;
use File::Slurp;
use MIME::Base64 qw( encode_base64 decode_base64 );
# Initialize
my $js = JavaScript::Duktape->new( max_memory => 1024 * 1024 * 1024 );
my $js = JavaScript::Duktape->new( max_memory => 256 * 1024 * 1024 );
$js->eval("var global = (function(){ return this; }).call(null);");
# Load the ExtendScript build
@ -325,15 +342,31 @@ $js->eval("log('SheetJS library version ' + XLSX.version);");
my $raw_data = encode_base64(read_file($ARGV[0], { binmode => ':raw' }), "");
$js->set("b64", $raw_data);
$js->eval(qq{
global.wb = XLSX.read(b64, {type: "base64"});
global.wb = XLSX.read(b64, {type: "base64", WTF:1});
global.ws = wb.Sheets[wb.SheetNames[0]];
void 0;
});
# Print first worksheet CSV
my $csv = $js->eval('XLSX.utils.sheet_to_csv(global.ws)');
print $csv
$js->eval('log(XLSX.utils.sheet_to_csv(global.ws))');
# Write XLSB file
my $xlsb = $js->eval("XLSX.write(global.wb, {type:'base64', bookType:'xlsb'})");
write_file("SheetJSDuk.xlsb", decode_base64($xlsb));
```
```
3) Download the SheetJS ExtendScript build and test file:
<CodeBlock language="bash">{`\
curl -LO https://cdn.sheetjs.com/xlsx-${current}/package/dist/xlsx.extendscript.js
curl -LO https://sheetjs.com/pres.xlsx`}
</CodeBlock>
4) Run the script:
```bash
perl SheetJSDuk.pl pres.xlsx
```
If the script succeeded, the data in the test file will be printed in CSV rows.
The script will also export `SheetJSDuk.xlsb`.

View File

@ -120,21 +120,26 @@ This string can be loaded into the JS engine and processed:
:::note
This demo was tested on 2023-07-26 using Rhino 1.7.14.
This demo was tested on 2023-10-26 against Rhino 1.7.14.
:::
0) Ensure Java is installed. Create a folder for the project, download the
[JAR](https://repo1.maven.org/maven2/org/mozilla/rhino/1.7.14/rhino-1.7.14.jar)
and rename to `rhino.jar`:
0) Ensure Java is installed.
1) Create a folder for the project:
```bash
mkdir sheetjs-java
cd sheetjs-java
```
2) Download the Rhino JAR and rename to `rhino.jar`:
```
curl -L -o rhino.jar https://repo1.maven.org/maven2/org/mozilla/rhino/1.7.14/rhino-1.7.14.jar
```
1) Download the SheetJS Standalone script and the test file. Save both files in
3) Download the SheetJS Standalone script and the test file. Save both files in
the project directory:
<ul>
@ -147,14 +152,14 @@ curl -LO https://cdn.sheetjs.com/xlsx-${current}/package/dist/xlsx.full.min.js
curl -LO https://sheetjs.com/pres.xlsx`}
</CodeBlock>
2) Download [`SheetJSRhino.zip`](pathname:///rhino/SheetJSRhino.zip) and unzip
4) Download [`SheetJSRhino.zip`](pathname:///rhino/SheetJSRhino.zip) and unzip
```bash
curl -LO https://docs.sheetjs.com/rhino/SheetJSRhino.zip
unzip SheetJSRhino.zip
```
3) Save the following code to `SheetJSRhino.java`:
5) Save the following code to `SheetJSRhino.java`:
```java title="SheetJSRhino.java"
/* sheetjs (C) 2013-present SheetJS -- https://sheetjs.com */
@ -184,14 +189,14 @@ public class SheetJSRhino {
}
```
4) Assemble `SheetJS.jar` from the demo code:
6) Assemble `SheetJS.jar` from the demo code:
```bash
javac -cp .:rhino.jar SheetJSRhino.java
jar -cf SheetJS.jar SheetJSRhino.class com/sheetjs/*.class xlsx.full.min.js
```
5) Test the program:
7) Test the program:
```bash
java -cp .:SheetJS.jar:rhino.jar SheetJSRhino pres.xlsx

View File

@ -133,7 +133,7 @@ This demo was tested in the following environments:
| Architecture | Swift | Date |
|:-------------|:--------|:-----------|
| `darwin-x64` | `5.8.1` | 2023-07-24 |
| `darwin-x64` | `5.9.0` | 2023-10-26 |
| `darwin-arm` | `5.9.0` | 2023-10-18 |
:::
@ -146,14 +146,22 @@ This example requires MacOS + Swift and will not work on Windows or Linux!
:::
0) Ensure Xcode is installed. Create a folder for the project:
0) Ensure Swift is installed by running the following command in the terminal:
```bash
swiftc --version
```
If the command is not found, install Xcode.
1) Create a folder for the project:
```bash
mkdir sheetjswift
cd sheetjswift
```
1) Download the SheetJS Standalone script and the test file. Save both files in
2) Download the SheetJS Standalone script and the test file. Save both files in
the project directory:
<ul>
@ -166,7 +174,7 @@ curl -LO https://cdn.sheetjs.com/xlsx-${current}/package/dist/xlsx.full.min.js
curl -LO https://sheetjs.com/pres.numbers`}
</CodeBlock>
2) Download the Swift scripts for the demo
3) Download the Swift scripts for the demo
- [`SheetJSCore.swift`](pathname:///swift/SheetJSCore.swift) Wrapper library
- [`main.swift`](pathname:///swift/main.swift) Command-line script
@ -177,13 +185,13 @@ curl -LO https://docs.sheetjs.com/swift/main.swift
```
3) Build the `SheetJSwift` binary:
4) Build the `SheetJSwift` program:
```bash
swiftc SheetJSCore.swift main.swift -o SheetJSwift
```
4) Test the program:
5) Test the program:
```bash
./SheetJSwift pres.numbers

View File

@ -262,7 +262,7 @@ This demo was tested in the following deployments:
| Architecture | Git Commit | Date |
|:-------------|:-----------|:-----------|
| `darwin-x64` | `2788d71` | 2023-07-24 |
| `darwin-x64` | `2788d71` | 2023-10-26 |
| `darwin-arm` | `2788d71` | 2023-10-18 |
| `win10-x64` | `2788d71` | 2023-10-09 |
| `win11-arm` | `2788d71` | 2023-09-25 |

View File

@ -1,5 +1,6 @@
---
title: SSF Number Formatter
hide_table_of_contents: true
---
As explained in ["Number Formats"](/docs/csf/features/nf), modern spreadsheet
@ -7,7 +8,7 @@ file formats separate "content" from "presentation". Instead of storing a
formatted value like `$3.50`, applications will store the underlying value
(`3.50`) and the number format (`$0.00`). Parsers are expected to render values.
The SheetJS `SSF` ("SpreadSheet Formatter") library formats numbers according
The SheetJS `SSF` ("SpreadSheet Format") library formats numbers according
to the number formatting rules defined in Excel and other spreadsheet software[^1]
A version of the library ships with the main file processing library. It is
@ -19,6 +20,36 @@ The library is also available for standalone use on the SheetJS CDN[^5].
The source code and project documentation is hosted on the SheetJS git server at
<https://git.sheetjs.com/sheetjs/sheetjs/src/branch/master/packages/ssf>
## Live Demo
The formatted text is calculated from the specified number format and value.
Please [report an issue](https://git.sheetjs.com/sheetjs/sheetjs/issues) if a
particular format is not supported.
```jsx live
function SheetJSSSF() {
const [fmt, setFmt] = React.useState("#,##0");
const [val, setVal] = React.useState(7262);
const format = (fmt, val) => { try {
return XLSX.SSF.format(fmt, val);
} catch(e) { return "ERROR: " + (e && e.message || e); } };
return ( <table>
<tr><td><b>Number Format</b></td><td>
<input type="text" value={fmt} onChange={e => setFmt(e.target.value)}/>
</td></tr>
<tr><td><b>Number Value</b></td><td>
<input type="text" value={val} onChange={e => setVal(+e.target.value)}/>
</td></tr>
<tr><td colspan="2"></td></tr>
<tr><td><b>Formatted Text</b></td><td>
<code>{format(fmt, val)}</code>
</td></tr>
</table> );
}
```
[^1]: The number formatting rules are sketched in ECMA-376. A rough grammar is defined in the MS-XLS specification.
[^2]: See [`read` in "Reading Files"](/docs/api/parse-options)
[^3]: See [`write` in "Writing Files"](/docs/api/write-options)

View File

@ -181,9 +181,12 @@ const config = {
{ from: '/docs/demos/vue', to: '/docs/demos/frontend/vue/' },
{ from: '/docs/demos/bundler', to: '/docs/demos/frontend/bundler/' },
{ from: '/docs/demos/legacy', to: '/docs/demos/frontend/legacy/' },
{ from: '/docs/demos/rollup', to: '/docs/demos/frontend/bundler/rollup/' },
{ from: '/docs/getting-started/demos/legacy', to: '/docs/demos/frontend/legacy/' },
{ from: '/docs/getting-started/demos/bundler', to: '/docs/demos/frontend/bundler/' },
/* cloud */
{ from: '/docs/demos/salesforce', to: '/docs/demos/cloud/salesforce/' },
{ from: '/docs/getting-started/demos/salesforce', to: '/docs/demos/cloud/salesforce/' },
{ from: '/docs/demos/aws', to: '/docs/demos/cloud/aws/' },
{ from: '/docs/demos/azure', to: '/docs/demos/cloud/azure/' },
{ from: '/docs/demos/netsuite', to: '/docs/demos/cloud/netsuite/' },
@ -214,6 +217,7 @@ const config = {
{ from: '/docs/getting-started/demos/network', to: '/docs/demos/net/network/' },
/* local */
{ from: '/docs/demos/clipboard', to: '/docs/demos/local/clipboard/' },
{ from: '/docs/getting-started/demos/clipboard', to: '/docs/demos/local/clipboard/' },
{ from: '/docs/demos/localfile', to: '/docs/demos/local/file/' },
{ from: '/docs/demos/data/indexeddb', to: '/docs/demos/local/indexeddb/' },
{ from: '/docs/demos/data/storageapi', to: '/docs/demos/local/storageapi/' },

View File

@ -1,40 +0,0 @@
import React from 'react';
import useBaseUrl from '@docusaurus/useBaseUrl';
import { CodePreview } from 'docusaurus-plugin-code-preview';
/*
export default function Playground(props) {
return (
<CodePreview
output={{
outputs: [
{
name: 'JavaScript',
value: 'javascript',
},
{
name: 'React',
value: 'react',
},
{
name: 'Angular',
value: 'angular',
},
{
name: 'Vue',
value: 'vue',
},
],
// This is the default selected option in the rendered component
defaultOutput: 'javascript',
}}
// Your existing options
/>
);
}
*/
export default function Playground(props) {
return <CodePreview {...props} src={useBaseUrl(props.src)} />;
}