AMD(定义)
每个独立的发布脚本均可在 https://cdn.sheetjs.com/ 处获得。
¥Each standalone release script is available at https://cdn.sheetjs.com/.
xlsx.full.min.js
支持 AMD,名称为 xlsx
,开箱即用。
¥xlsx.full.min.js
supports AMD with name xlsx
out of the box.
https://cdn.sheetjs.com/xlsx-0.20.3/package/dist/xlsx.full.min.js is the URL for 0.20.3
当按文件名引用时,AMD 加载程序通常会忽略文件扩展名。
¥When referencing by file name, AMD loaders typically omit the file extension.
实际文件名是 xlsx.full.min.js
,但示例使用名称 xlsx.full.min
标识脚本
¥The actual file name is xlsx.full.min.js
, but the examples identify the script
using the name xlsx.full.min
监视存储库 或订阅 RSS 订阅 以在新版本发布时收到通知!
¥Watch the repo or subscribe to the RSS feed to be notified when new versions are released!
NetSuite
下载脚本并上传到文件柜后,必须在 @NAmdConfig
配置文件中添加模块别名:
¥After downloading the script and uploading to the file cabinet, a module alias
must be added to the @NAmdConfig
configuration file:
{
"paths": {
"xlsx": "/path/to/xlsx.full.min"
}
}
添加后,SuiteScripts 可以使用名称 xlsx
引用该包:
¥Once added, SuiteScripts can reference the package using the name xlsx
:
/**
* @NApiVersion 2.x
* ... more options ...
* @NAmdConfig ./JsLibraryConfig.json
*/
define(['N/file', 'xlsx'], function(file, XLSX) {
// ... use XLSX here ...
});
更多详细信息包含在 NetSuite 演示 中
¥More details are included in the NetSuite demo
NetSuite 用户报告 错误源于 Oracle 问题。下面显示了错误消息示例。
¥NetSuite users reported errors that stem from an Oracle issue. A sample error message is shown below.
Fail to evaluate script: com.netsuite.suitescript.scriptobject.GraalValueAdapter@68d0f09d
这是 NetSuite 的一个错误。只有 Oracle 可以修复该错误!
¥This is a NetSuite bug. Only Oracle can fix the bug!
强烈建议通过 Oracle 支持升级问题。
¥It is strongly encouraged to escalate the issue with Oracle support.
NetSuite 用户已报告通过以下解决方法取得了成功:
¥NetSuite users have reported success with the following workaround:
-
在文本编辑器中打开脚本并在代码中搜索
define(
。¥Open the script in a text editor and search for
define(
in the code.
只会有一个实例:
¥There will be exactly one instance:
define("xlsx",function(){
将 xlsx
替换为 sheetjs
:
¥Replace the xlsx
with sheetjs
:
define("sheetjs",function(){
-
在 JSON 配置中使用新名称:
¥Use the new name in the JSON configuration:
{
"paths": {
"sheetjs": "/path/to/xlsx.full.min"
}
}
-
在
define
函数调用的数组参数中使用新名称:¥Use the new name in the array argument to the
define
function call:
/**
* @NApiVersion 2.x
* ... more options ...
* @NAmdConfig ./JsLibraryConfig.json
*/
define(['N/file', 'sheetjs'], function(file, XLSX) {
// ^^^^^^^ ^^^^
// new module name same variable
// ... use XLSX here ...
});
SAP UI5
下载脚本后,可以上传到 UI5 项目并在 sap.ui.define
调用中加载:
¥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
})
复制和粘贴代码不适用于 SheetJS 脚本,因为它们包含可能会被破坏的 Unicode 字符。应下载独立脚本并将其手动上传到项目中。
¥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
独立脚本必须使用路径 xlsx
的别名。
¥The standalone script must be aliased to the path xlsx
.
requirejs.config
函数可以通过 paths
键定义别名:
¥The requirejs.config
function can define aliases through the paths
key:
requirejs.config({
paths: {
xlsx: [ './xlsx.full.min' ]
}
});
配置别名后,应用代码可以自由要求 xlsx
:
¥After configuring the alias, app code can freely require xlsx
:
require(['xlsx'], function(XLSX) {
// ... use XLSX here
});
详情请参阅 RequireJS 演示
¥See the RequireJS demo for details
Dojo 工具包
¥Dojo Toolkit
多年来,Dojo 已经改变了模块加载策略。这些示例是使用 Dojo 1.17.3
进行测试的。不保证它们可以与其他版本一起使用。
¥Dojo has changed module loading strategies over the years. These examples were
tested with Dojo 1.17.3
. They are not guaranteed to work with other versions.
"Dojo 工具包" 中包含在线演示
¥Live demos are included in "Dojo Toolkit"
独立脚本添加 window.XLSX
,因此建议在函数参数中使用 _XLSX
,并在回调中使用 XLSX
访问库:
¥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(
_XLSX // !! NOTE: this is not XLSX! A different variable name must be used
) {
console.log(XLSX.version); // use XLSX in the callback
})
同步加载
¥Synchronous Loading
当 async
设置为 false
或 0
时,可以在 require
调用中直接引用脚本。
¥When async
is set to false
or 0
, the scripts can be directly referenced in
require
calls.
<script src="dojo.js" data-dojo-config="isDebug:1, async:0"></script>
<script>
require([
"https://cdn.sheetjs.com/xlsx-0.20.3/package/dist/xlsx.full.min.js"
], function(
_XLSX // !! NOTE: this is not XLSX! A different variable name must be used
) {
// ... use XLSX here
});
</script>
异步加载
¥Asynchronous Loading
当启用 async
时,Dojo 将只识别名称 xlsx
。config 对象可以将包名称映射到脚本:
¥When async
is enabled, Dojo will only understand the name xlsx
. The config
object can map package names to scripts:
<script>
// This setting must appear *before* loading dojo.js
dojoConfig = {
packages: [
{
name: "xlsx",
// if self-hosting the script, location should be a folder relative to baseUrl setting
location: "https://cdn.sheetjs.com/xlsx-0.20.3/package/dist",
// name of the script (without the .js extension)
main: "xlsx.full.min"
}
]
};
</script>
<script src="dojo.js" data-dojo-config="isDebug:1, async:1"></script>
<script>
require(["xlsx"], function(_XLSX) {
// ... use XLSX here
});
</script>