netsuite-amd

This commit is contained in:
SheetJS 2024-01-17 15:22:38 -05:00
parent 9698f15b32
commit 963168e7b4
10 changed files with 140 additions and 107 deletions

@ -36,18 +36,34 @@ new versions are released!
## NetSuite
After adding to the File Cabinet, scripts can be referenced in `define` calls
in SuiteScripts. For example, if the `xlsx.full.min.js` script is placed in the
same folder as the SuiteScript, the relative import `"./xlsx.full.min"` works:
After downloading the script and uploading to the file cabinet, a module alias
must be added to the `@NAmdConfig` configuration file:
```js
define(['N/file', './xlsx.full.min'], function(file, XLSX) {
// ... use XLSX here
})
```json title="JsLibraryConfig.json"
{
"paths": {
// highlight-next-line
"xlsx": "/path/to/xlsx.full.min"
}
}
```
As explained in the [NetSuite demo](/docs/demos/cloud/netsuite), module aliases
can be created in config files referenced via `@NAmdConfig` comments.
Once added, SuiteScripts can reference the package using the name `xlsx`:
```js title="SuiteScript"
/**
* @NApiVersion 2.x
* ... more options ...
// highlight-next-line
* @NAmdConfig ./JsLibraryConfig.json
*/
// highlight-next-line
define(['N/file', 'xlsx'], function(file, XLSX) {
// ... use XLSX here ...
});
```
**More details are included in the [NetSuite demo](/docs/demos/cloud/netsuite#installation)**
## SAP UI5

@ -7,6 +7,8 @@ pagination_next: demos/frontend/index
import DocCardList from '@theme/DocCardList';
import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
Each valid number in Excel can be represented as an "IEEE754 double"[^1].
With full support for IEEE754 doubles and singles, JavaScript is an excellent
language for mathematics and statistical analysis. It has also proven to be a
viable platform for machine learning.
@ -88,8 +90,8 @@ entries will be converted to quiet `NaN` values.
#### Extracting Worksheet Data
The SheetJS `sheet_to_json`[^1] method with the option `header: 1`[^2] generates
an array of arrays from a worksheet object. The result is in row-major order:
The SheetJS `sheet_to_json`[^2] method with the option `header: 1` generates an
array of arrays from a worksheet object. The result is in row-major order:
```js
const aoa = XLSX.utils.sheet_to_json(worksheet, {header: 1});
@ -247,9 +249,9 @@ const petal_length = Float64Array.from(aoa[2].slice(1));
### Writing to Sheets
The SheetJS `aoa_to_sheet`[^1] method can generate a worksheet from an array of
arrays. Similarly, `sheet_add_aoa`[^2] can add an array of arrays of data into
an existing worksheet object. The `origin` option[^3] controls where data will
The SheetJS `aoa_to_sheet`[^3] method can generate a worksheet from an array of
arrays. Similarly, `sheet_add_aoa`[^4] can add an array of arrays of data into
an existing worksheet object. The `origin` option[^5] controls where data will
be written in the worksheet.
Neither method understands typed arrays, so data columns must be converted to
@ -407,6 +409,8 @@ function SheetJSeriesToCols() { return (<button onClick={() => {
</details>
[^1]: See [`aoa_to_sheet` in "Utilities"](/docs/api/utilities/array#array-of-arrays-input)
[^2]: See [`sheet_add_aoa` in "Utilities"](/docs/api/utilities/array#array-of-arrays-input)
[^3]: See [the `origin` option of `sheet_add_aoa` in "Utilities"](/docs/api/utilities/array#array-of-arrays-input)
[^1]: See ["Underlying Values" in "Cell Objects"](/docs/csf/cell#excel-values) for more details
[^2]: See [`sheet_to_json` in "Utilities"](/docs/api/utilities/array#array-output)
[^3]: See [`aoa_to_sheet` in "Utilities"](/docs/api/utilities/array#array-of-arrays-input)
[^4]: See [`sheet_add_aoa` in "Utilities"](/docs/api/utilities/array#array-of-arrays-input)
[^5]: See [the `origin` option of `sheet_add_aoa` in "Utilities"](/docs/api/utilities/array#array-of-arrays-input)

@ -277,4 +277,4 @@ binding is possible using the `$parent` and `$index` binding context properties:
</details>
[^1]: Project hosted at <https://github.com/dcneiner/Downloadify>
[^1]: The project does not have a separate website. The source repository is hosted on [GitHub](https://github.com/dcneiner/Downloadify)

@ -4,8 +4,8 @@ pagination_next: demos/net/upload/index
---
<head>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/superagent@7.1.1/dist/superagent.min.js"></script>
<script src="https://unpkg.com/axios@1.6.5/dist/axios.min.js"></script>
<script src="https://unpkg.com/superagent@8.1.2/dist/superagent.min.js"></script>
</head>
import current from '/version.js';
@ -41,9 +41,9 @@ functions functions can send files to clients.
Most interesting spreadsheet files are binary data that contain byte sequences
that represent invalid UTF-8 characters.
The APIs generally have a way to control the interpretation of the downloaded
data. The `arraybuffer` response type usually forces the data to be presented
as an `ArrayBuffer` which can be parsed directly with the SheetJS `read` method[^1].
APIs generally provide options to control how downloaded data is interpreted.
The `arraybuffer` response type usually forces the data to be presented as an
`ArrayBuffer` object which can be parsed with the SheetJS `read` method[^1].
The following example shows the data flow using `fetch` to download files:
@ -71,13 +71,21 @@ const wb = XLSX.read(ab);
## Browser Demos
The included demos focus on an editable table.
When the page is accessed, the browser will attempt to download <https://sheetjs.com/pres.numbers>
and read the workbook. The old table will be replaced with a table whose
contents match the first worksheet. The table is generated using the SheetJS
`sheet_to_html` method[^2]
:::note Tested Deployments
Each browser demo was tested in the following environments:
| Browser | Date |
|:------------|:-----------|
| Chrome 120 | 2024-01-15 |
| Safari 17.2 | 2024-01-15 |
:::
### XMLHttpRequest
@ -289,8 +297,8 @@ function SheetJSAxiosDL() {
#### superagent
[`superagent`](https://github.com/visionmedia/superagent) is a network request
library with a "Fluent Interface". Calling the `responseType` method with
[`superagent`](https://ladjs.github.io/superagent/) is a network request library
with a "Fluent Interface". Calling the `responseType` method with
`"arraybuffer"` will ensure the final response object is an `ArrayBuffer`:
```js
@ -380,7 +388,7 @@ https.get('https://sheetjs.com/pres.numbers', function(res) {
:::note
This demo was last tested on 2023 August 29 against NodeJS `20.5.1`
This demo was last tested on 2024 January 15 against NodeJS `20.11.0`
:::
@ -392,12 +400,25 @@ npm i --save https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz`}
2) Copy the `SheetJSHTTPSGet.js` code snippet to a file `SheetJSHTTPSGet.js`
3) Run `node SheetJSHTTPSGet.js`. It will print CSV contents of the test file.
3) Run the script:
```bash
node SheetJSHTTPSGet.js
```
If successful, the script will print CSV contents of the test file.
</details>
### fetch
:::caution pass
Experimental support for `fetch` was introduced in NodeJS `16.15.0`. It will be
considered stable in NodeJS LTS version `22`.
:::
The `fetch` implementation has the same return types as the browser version:
```js
@ -414,7 +435,7 @@ async function parse_from_url(url) {
:::note
This demo was last tested on 2023 August 29 against NodeJS `20.5.1`
This demo was last tested on 2024 January 15 against NodeJS `20.11.0`
:::
@ -445,7 +466,13 @@ async function parse_from_url(url) {
})();
```
3) Run `node SheetJSFetch.js`. It will print CSV contents of the test file.
3) Run the script:
```bash
node SheetJSFetch.js
```
If successful, the script will print CSV contents of the test file.
</details>
@ -487,7 +514,7 @@ request(url, {encoding: null}, function(err, res, data) {
:::note
This demo was last tested on 2023 August 29 against request `2.88.2`
This demo was last tested on 2024 January 15 against request `2.88.2`
:::
@ -499,7 +526,13 @@ npm i --save https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz request
2) Copy the `SheetJSRequest.js` code snippet to a file `SheetJSRequest.js`
3) Run `node SheetJSRequest.js`. It will print CSV contents of the test file.
3) Run the script:
```bash
node SheetJSRequest.js
```
If successful, the script will print CSV contents of the test file.
</details>
@ -523,14 +556,14 @@ async function workbook_dl_axios(url) {
:::note
This demo was last tested on 2023 August 29 against Axios `1.5.0`
This demo was last tested on 2024 January 15 against Axios `1.6.5`
:::
1) Install the [NodeJS module](/docs/getting-started/installation/nodejs)
<CodeBlock language="bash">{`\
npm i --save https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz axios@1.5.0`}
npm i --save https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz axios@1.6.5`}
</CodeBlock>
2) Save the following to `SheetJSAxios.js`:
@ -553,7 +586,13 @@ async function workbook_dl_axios(url) {
})();
```
3) Run `node SheetJSAxios.js`. It will print CSV contents of the test file.
3) Run the script:
```bash
node SheetJSAxios.js
```
If successful, the script will print CSV contents of the test file.
</details>

@ -5,7 +5,7 @@ pagination_next: demos/net/server/index
---
<head>
<script src="https://unpkg.com/axios@1.6.2/dist/axios.min.js"></script>
<script src="https://unpkg.com/axios@1.6.5/dist/axios.min.js"></script>
<script src="https://unpkg.com/superagent@8.1.2/dist/superagent.min.js"></script>
</head>
@ -101,21 +101,21 @@ When the upload button is clicked, the browser will build up a new workbook,
generate a XLSX file, upload it to <https://s2c.sheetjs.com> and show the
response. If the process was successful, a HTML table will be displayed
### XMLHttpRequest
This demo uses [the code snippet from the intro](#uploading-binary-data).
:::note Tested Deployments
This browser demo was tested in the following environments:
Each browser demo was tested in the following environments:
| Browser | Date |
|:------------|:-----------|
| Chrome 119 | 2023-11-19 |
| Safari 17.1 | 2023-11-19 |
| Chrome 120 | 2024-01-15 |
| Safari 17.2 | 2023-01-15 |
:::
### XMLHttpRequest
This demo uses [the code snippet from the intro](#uploading-binary-data).
<details><summary><b>Live demo</b> (click to show)</summary>
This demo starts from an array of arrays of data. When the button is clicked, a
@ -206,17 +206,6 @@ fdata.append('file', new File([data], 'sheetjs.xlsx'));
fetch("https://s2c.sheetjs.com", { method: "POST", body: fdata });
```
:::note Tested Deployments
This browser demo was tested in the following environments:
| Browser | Date |
|:------------|:-----------|
| Chrome 119 | 2023-11-19 |
| Safari 17.1 | 2023-11-19 |
:::
<details><summary><b>Live demo</b> (click to show)</summary>
This demo uses `fetch` to upload data to <https://s2c.sheetjs.com>. It will parse
@ -309,17 +298,6 @@ fdata.append('file', new File([data], 'sheetjs.xlsx'));
axios("https://s2c.sheetjs.com", { method: "POST", data: fdata });
```
:::note Tested Deployments
This demo was tested using the standalone script in the following environments:
| Browser | Version | Date |
|:------------|---------|:-----------|
| Chrome 119 | `1.6.2` | 2023-11-19 |
| Safari 17.1 | `1.6.2` | 2023-11-19 |
:::
<details><summary><b>Live demo</b> (click to show)</summary>
This demo uses `axios` to upload data to <https://s2c.sheetjs.com>. It will parse
@ -392,8 +370,8 @@ function SheetJSAxiosUL() {
#### superagent
[`superagent`](https://github.com/visionmedia/superagent) is a network request
library with a "Fluent Interface".
[`superagent`](https://ladjs.github.io/superagent/) is a network request library
with a "Fluent Interface".
The `send` method accepts a `FormData` object as the first argument:
@ -419,17 +397,6 @@ fdata.append('file', new File([data], 'sheetjs.xlsx'));
superagent.post("https://s2c.sheetjs.com").send(fd);
```
:::note Tested Deployments
This demo was tested using the standalone script in the following environments:
| Browser | Version | Date |
|:------------|---------|:-----------|
| Chrome 119 | `8.1.2` | 2023-11-19 |
| Safari 17.1 | `8.1.2` | 2023-11-19 |
:::
<details><summary><b>Live demo</b> (click to show)</summary>
This demo uses `superagent` to upload data to <https://s2c.sheetjs.com>. It will

@ -5,15 +5,22 @@ title: Synthetic DOM
import current from '/version.js';
import CodeBlock from '@theme/CodeBlock';
SheetJS offers three methods to directly process HTML DOM TABLE elements[^1]:
[SheetJS](https://sheetjs.com) is a JavaScript library for reading and writing
data from spreadsheets.
- `table_to_sheet` generates a SheetJS worksheet[^2] from a TABLE element
- `table_to_book` generates a SheetJS workbook[^3] from a TABLE element
- `sheet_add_dom` adds data from a TABLE element to an existing worksheet
SheetJS offers three methods to directly process HTML DOM TABLE elements:
- `table_to_sheet`[^1] generates a SheetJS worksheet[^2] from a TABLE element
- `table_to_book`[^3] generates a SheetJS workbook[^4] from a TABLE element
- `sheet_add_dom`[^5] adds data from a TABLE element to an existing worksheet
These methods work in the web browser. NodeJS and other server-side platforms
traditionally lack a DOM implementation, but third-party modules fill the gap.
This demo covers synthetic DOM implementations for non-browser platforms. We'll
explore how to use SheetJS DOM methods in server-side environments to parse
tables and export data to spreadsheets.
:::tip pass
The most robust approach for server-side processing is to automate a headless
@ -21,11 +28,9 @@ web browser. ["Browser Automation"](/docs/demos/net/headless) includes demos.
:::
This demo covers synthetic DOM implementations for non-browser platforms.
## Integration Details
SheetJS API methods use DOM features that may not be available.
SheetJS methods use features that may be missing from some DOM implementations.
### Table rows
@ -55,8 +60,8 @@ tbl.rows.forEach(row => row.cells = Array.from(row.getElementsByTagName("td")));
### JSDOM
JSDOM is a DOM implementation for NodeJS. The synthetic DOM elements are
compatible with SheetJS methods.
[JSDOM](https://git.io/jsdom) is a DOM implementation for NodeJS. The synthetic
DOM elements are compatible with SheetJS methods.
The following example scrapes the first table from the file `SheetJSTable.html`
and generates a XLSX workbook:
@ -82,7 +87,7 @@ XLSX.writeFile(workbook, "SheetJSDOM.xlsx");
<details><summary><b>Complete Demo</b> (click to show)</summary>
:::note
:::note Tested Deployments
This demo was last tested on 2023 September 10 against JSDOM `22.1.0`
@ -122,7 +127,7 @@ the following patches were needed:
<details><summary><b>Complete Demo</b> (click to show)</summary>
:::note
:::note Tested Deployments
This demo was last tested on 2023 September 10 against HappyDOM `11.0.2`
@ -152,8 +157,8 @@ The script will create a file `SheetJSHappyDOM.xlsx` that can be opened.
### XMLDOM
XMLDOM provides a DOM framework for NodeJS. For the tested version (`0.8.10`),
the following patches were needed:
[XMLDOM](https://xmldom.org/) provides a DOM framework for NodeJS. For the
tested version (`0.8.10`), the following patches were needed:
- TABLE `rows` property (explained above)
- TR `cells` property (explained above)
@ -169,7 +174,7 @@ Object.defineProperty(tbl.__proto__, "innerHTML", { get: function() {
<details><summary><b>Complete Demo</b> (click to show)</summary>
:::note
:::note Tested Deployments
This demo was last tested on 2023 September 10 against XMLDOM `0.8.10`
@ -206,13 +211,13 @@ can be shimmed, but it is strongly recommended to use a more compliant library.
:::
CheerioJS provides a DOM-like framework for NodeJS. Many features were missing.
[CheerioJS](https://cheerio.js.org/) provides a DOM-like framework for NodeJS.
[`SheetJSCheerio.js`](pathname:///dom/SheetJSCheerio.js) implements the missing
features to ensure that SheetJS DOM methods can process TABLE elements.
<details><summary><b>Complete Demo</b> (click to show)</summary>
:::note
:::note Tested Deployments
This demo was last tested on 2023 September 10 against Cheerio `1.0.0-rc.12`
@ -250,8 +255,8 @@ The script will create a file `SheetJSCheerio.xlsx` that can be opened.
### DenoDOM
DenoDOM provides a DOM framework for Deno. For the tested version (`0.1.38`),
the following patches were needed:
[DenoDOM](https://deno.land/x/deno_dom) provides a DOM framework for Deno. For
the tested version (`0.1.38`), the following patches were needed:
- TABLE `rows` property (explained above)
- TR `cells` property (explained above)
@ -283,7 +288,7 @@ XLSX.writeFile(workbook, "SheetJSDenoDOM.xlsx");`}
<details><summary><b>Complete Demo</b> (click to show)</summary>
:::note
:::note Tested Deployments
This demo was last tested on 2023 September 10 against DenoDOM `0.1.38`
@ -301,6 +306,8 @@ The script will create a file `SheetJSDenoDOM.xlsx` that can be opened.
</details>
[^1]: See ["HTML Table Input" in "Utilities"](/docs/api/utilities/html#html-table-input)
[^1]: See [`table_to_sheet` in "HTML" Utilities](/docs/api/utilities/html#create-new-sheet)
[^2]: See ["Worksheet Object" in "SheetJS Data Model"](/docs/csf/book) for more details.
[^3]: See ["Workbook Object" in "SheetJS Data Model"](/docs/csf/book) for more details.
[^3]: See [`table_to_book` in "HTML" Utilities](/docs/api/utilities/html#create-new-sheet)
[^4]: See ["Workbook Object" in "SheetJS Data Model"](/docs/csf/book) for more details.
[^5]: See [`sheet_add_dom` in "HTML" Utilities](/docs/api/utilities/html#add-to-sheet)

@ -301,6 +301,8 @@ If the emulator is not running, `nativescript` may fail with the message:
Emulator start failed with: No emulator image available for device identifier 'undefined'.
```
:::
6) From the project folder, install the library:
<CodeBlock language="bash">{`\

@ -324,7 +324,7 @@ It should print `Hello world!`
:::caution pass
If the output is not `Hello world!` or if there is an error, please report the
issue to the `pg` connector project for further diagnosis[^8]
issue to the `pg` connector project for further diagnosis.
:::
@ -417,5 +417,4 @@ psql SheetJSPG -c 'SELECT * FROM "Presidents";'
[^4]: See ["Workbook Helpers" in "Utilities"](/docs/api/utilities/wb) for details on `book_new` and `book_append_sheet`.
[^5]: See [`writeFile` in "Writing Files"](/docs/api/write-options)
[^6]: See [`sheet_to_json` in "Utilities"](/docs/api/utilities/array#array-output)
[^7]: The [`pg-format`](https://npm.im/pg-format) package is available on the public NPM registry. Even though the project is marked as deprecated, the official [`pg` website still recommends `pg-format`](https://node-postgres.com/features/queries#parameterized-query:~:text=use%20pg%2Dformat%20package%20for%20handling%20escaping)
[^8]: The official [issue tracker](https://github.com/brianc/node-postgres/issues) is hosted on GitHub
[^7]: The [`pg-format`](https://npm.im/pg-format) package is available on the public NPM registry. Even though the project is marked as deprecated, the official [`pg` website still recommends `pg-format`](https://node-postgres.com/features/queries#parameterized-query:~:text=use%20pg%2Dformat%20package%20for%20handling%20escaping)

@ -310,7 +310,7 @@ It should print `Hello world!`
:::caution pass
If the output is not `Hello world!` or if there is an error, please report the
issue to the `mysql2` connector project for further diagnosis[^8]
issue to the `mysql2` connector project for further diagnosis.
:::
@ -391,11 +391,10 @@ If the server is running locally, the command will be:
mysql -D SheetJSMariaDB -e 'SELECT * FROM `Presidents`;'
```
[^1]: See [the `mysql2` repository](https://github.com/sidorares/node-mysql2) for more info.
[^1]: See [the official `mysql2` website](https://sidorares.github.io/node-mysql2/docs) for more info.
[^2]: See [`json_to_sheet` in "Utilities"](/docs/api/utilities/array#array-of-objects-input)
[^3]: See ["Sheet Objects"](/docs/csf/sheet) in "SheetJS Data Model" for more details.
[^4]: See ["Workbook Helpers" in "Utilities"](/docs/api/utilities/wb) for details on `book_new` and `book_append_sheet`.
[^5]: See [`writeFile` in "Writing Files"](/docs/api/write-options)
[^6]: See [`sheet_to_json` in "Utilities"](/docs/api/utilities/array#array-output)
[^7]: The `mysql2` connector library `escapeId` method is not mentioned in the documentation but is present in the TypeScript definitions.
[^8]: The official [issue tracker](https://github.com/sidorares/node-mysql2/issues) is hosted on GitHub

@ -26,7 +26,7 @@ This demo was verified by NetSuite consultants in the following deployments:
|:----------------|:---------------|:-----------|
| ScheduledScript | 2.1 | 2023-12-13 |
| Restlet | 2.1 | 2023-10-05 |
| Suitelet | 2.1 | 2023-12-22 |
| Suitelet | 2.1 | 2024-01-17 |
| MapReduceScript | 2.1 | 2023-12-07 |
:::