This commit is contained in:
SheetJS 2022-06-22 15:25:24 -04:00
parent f3b4f8067a
commit c78829079f
4 changed files with 70 additions and 8 deletions

View File

@ -63,7 +63,7 @@ $ pnpm install --save file:vendor/xlsx-${current}.tgz`}
</TabItem>
<TabItem value="yarn" label="Yarn" default>
<pre><code parentName="pre" {...{"className": "language-bash"}}>{`\
$ yarn add --save file:vendor/xlsx-0.18.7.tgz`}
$ yarn add --save file:vendor/xlsx-${current}.tgz`}
</code></pre>
</TabItem>
</Tabs>

View File

@ -1,7 +1,7 @@
---
sidebar_position: 6
sidebar_custom_props:
summary: NetSuite, RequireJS and other module systems
summary: NetSuite, SAP UI5, RequireJS
---
import current from '/version.js';
@ -14,6 +14,15 @@ Each standalone release script is available at <https://cdn.sheetjs.com/>.
<div><a href={`https://cdn.sheetjs.com/xlsx-${current}/package/dist/xlsx.full.min.js`}>https://cdn.sheetjs.com/xlsx-{current}/package/dist/xlsx.full.min.js</a> is the URL for {current}</div><br/>
:::note
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`.
:::
## NetSuite
After downloading the script, it can be referenced directly in `define` calls
@ -28,6 +37,31 @@ define(['N/file', './xlsx.full.min'], function(file, XLSX) {
As explained in the [NetSuite demo](../getting-started/demos/netsuite), module
aliases are created in config files referenced via `@NAmdConfig` comments.
## SAP UI5
After downloading the script, it can be uploaded to the UI5 project and loaded
in the `sap.ui.define` call:
```js
sap.ui.define([
/* ... other libraries ... */
"path/to/xlsx.full.min"
], function(/* ... variables for the other libraries ... */, XLSX) {
// use XLSX here
})
```
:::warning
The [SAP Website has a note about including third-party JS libraries.](https://blogs.sap.com/2017/04/30/how-to-include-third-party-libraries-modules-in-sapui5/SAPUI5)
It recommends copying and pasting JavaScript code.
**Copy and pasting code does not work** for SheetJS scripts as they contain
Unicode characters that may be mangled. The standalone script should be
downloaded and manually uploaded to the project.
:::
## RequireJS
After downloading the script, it can be referenced directly in `require` calls:

View File

@ -156,7 +156,7 @@ var wb = XLSX.read(ab); // parse workbook
**This is how it should work**.
[There are outstanding bugs](https://github.com/OfficeDev/office-js/issues/2186)
[There are outstanding bugs in Excel.](https://github.com/OfficeDev/office-js/issues/2186)
For the purposes of this demo, a Base64-encoded file will be used. The
workaround involves fetching that Base64 file, getting the text, and parsing

View File

@ -10,6 +10,8 @@ sidebar_position: 5
`XLSX.SSF` is an embedded version of the [format library](https://github.com/SheetJS/sheetjs/tree/master/packages/ssf).
`XLSX.CFB` is an embedded version of the [container library](https://github.com/sheetjs/js-cfb).
## Parsing functions
`XLSX.read(data, read_opts)` attempts to parse `data`.
@ -20,16 +22,18 @@ Parse options are described in the [Parsing Options](./api/parse-options) sectio
## Writing functions
`XLSX.write(wb, write_opts)` attempts to write the workbook `wb`
`XLSX.write(wb, write_opts)` attempts to write the workbook `wb`.
`XLSX.writeXLSX(wb, write_opts)` attempts to write the workbook in XLSX format.
`XLSX.writeFile(wb, filename, write_opts)` attempts to write `wb` to `filename`.
In browser-based environments, it will attempt to force a client-side download.
`XLSX.writeFileXLSX(wb, filename, write_opts)` attempts to write an XLSX file.
`XLSX.writeFileAsync(filename, wb, o, cb)` attempts to write `wb` to `filename`.
If `o` is omitted, the writer will use the third argument as the callback.
`XLSX.stream` contains a set of streaming write functions.
Write options are described in the [Writing Options](./api/write-options) section.
## Utilities
@ -59,7 +63,7 @@ The following are described in the [Utility Functions](./api/utilities):
- `table_to_sheet` converts a DOM TABLE element to a worksheet.
- `sheet_add_aoa` adds an array of arrays of JS data to an existing worksheet.
- `sheet_add_json` adds an array of JS objects to an existing worksheet.
- `sheet_add_dom` adds data from a DOM TABLE element to an existing worksheet.
**Exporting:**
@ -69,7 +73,31 @@ The following are described in the [Utility Functions](./api/utilities):
- `sheet_to_html` generates HTML output.
- `sheet_to_formulae` generates a list of the formulae (with value fallbacks).
**Miscellaneous**
- `format_cell` generates the text value for a cell (using number formats).
- `sheet_set_array_formula` adds an array formula to a worksheet
## Platform-Specific Functions
### NodeJS Streaming Write functions
`XLSX.stream` contains a set of streaming write functions for NodeJS streams:
- `to_csv(sheet, opts)` streams CSV rows
- `to_html(sheet, opts)` streams an HTML table incrementally
- `to_json(sheet, opts)` streams JS objects (object-mode stream)
### ESM Helpers
Due to broad inconsistencies in ESM implementations, the `mjs` build does not
import any dependencies. Instead, they must be manually passed to the library:
`XLSX.set_cptable` sets the internal `codepage` instance. This provides support
for different language encodings.
`XLSX.set_fs` set `fs` instance (using `readFileSync` and `writeFileSync`). This
provides NodeJS ESM support for `XLSX.readFile` and `XLSX.writeFile`.
`XLSX.utils.set_readable` supplies a NodeJS `stream.Readable` constructor. This
provides NodeJS ESM support for the streaming operations.