4.4 KiB
pagination_prev | pagination_next | sidebar_position | sidebar_custom_props | ||
---|---|---|---|---|---|
getting-started/index | getting-started/examples/index | 4 |
|
import current from '/version.js'; import CodeBlock from '@theme/CodeBlock';
AMD (define)
Each standalone release script is available at https://cdn.sheetjs.com/.
xlsx.full.min.js
supports AMD with name xlsx
out of the box.
https://cdn.sheetjs.com/xlsx-{current}/package/dist/xlsx.full.min.js is the URL for {current}
:::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
.
:::
:::tip pass
Watch the repo or subscribe to the RSS feed to be notified when 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:
define(['N/file', './xlsx.full.min'], function(file, XLSX) {
// ... use XLSX here
})
As explained in the NetSuite demo, module aliases
can be 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:
sap.ui.define([
/* ... other libraries ... */
"path/to/xlsx.full.min"
], function(/* ... variables for the other libraries ... */, XLSX) {
// use XLSX here
})
:::warning
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
:::caution
The standalone script must be aliased to the path xlsx
.
The requirejs.config
function can define aliases through the paths
key:
requirejs.config({
paths: {
xlsx: [ './xlsx.full.min' ]
}
});
:::
After configuring the alias, app code can freely require xlsx
:
require(['xlsx'], function(XLSX) {
// ... use XLSX here
});
Dojo Toolkit
Dojo has changed module loading strategies over the years. These examples were
tested with Dojo 1.10.4
and are not guaranteed to work with other versions.
Live demos are included in "Dojo Toolkit"
:::caution
The standalone scripts add window.XLSX
, so it is recommended to use _XLSX
in the function arguments and access the library with XLSX
in the callback:
require(["xlsx"], function(
// highlight-next-line
_XLSX // !! NOTE: this is not XLSX! A different variable name must be used
) {
// highlight-next-line
console.log(XLSX.version); // use XLSX in the callback
})
:::
Synchronous Loading
When async
is set to false
or 0
, the scripts can be directly referenced in
require
calls.
{`\
`}Asynchronous Loading
When async
is enabled, Dojo will only understand the name xlsx
. The config
object can map package names to scripts:
{`\
`}