Standalone Browser Scripts独立浏览器脚本
Each standalone release script is available at https://cdn.sheetjs.com/.每个独立版本脚本都可以在https://cdn.sheetjs.com/上获得。
<!-- use version 0.18.9 -->
<script lang="javascript" src="https://cdn.sheetjs.com/xlsx-0.18.9/package/dist/xlsx.full.min.js"></script>
The latest
tag references the latest version and updates with each release:latest
标签引用了最新版本和每个版本的更新:
<!-- use the latest version -->
<script lang="javascript" src="https://cdn.sheetjs.com/xlsx-latest/package/dist/xlsx.full.min.js"></script>
Browser Scripts浏览器脚本
xlsx.full.min.js
is the complete standalone script. 是完整的独立脚本。It includes support for reading and writing many spreadsheet formats.它包括对许多电子表格格式的读写支持。
<!-- use xlsx.full.min.js from version 0.18.9 -->
<script lang="javascript" src="https://cdn.sheetjs.com/xlsx-0.18.9/package/dist/xlsx.full.min.js"></script>
A slimmer build is generated at 在dist/xlsx.mini.min.js
. dist/xlsx.mini.min.js
上生成了更瘦的构建。Compared to full build:与完整版本相比:
codepage library skipped (no support for XLS encodings)跳过了代码页库(不支持XLS编码)no support for XLSB / XLS / Lotus 1-2-3 / SpreadsheetML 2003 / Numbers不支持XLSB/XLS/Lotus 1-2-3/SpreadsheetML 2003/Numbersnode stream utils removed已删除节点流utils
How to integrate the mini build如何集成迷你构建 (click to show)
Replace references to 用xlsx.full.min.js
with xlsx.mini.min.js
. xlsx.mini.min.js
替换对xlsx.full.min.js
的引用。Starting from scratch, a single script tag should be added at the top of the HTML page:从头开始,应在HTML页面顶部添加一个script
标记:
<!-- use xlsx.mini.min.js from version 0.18.9 -->
<script lang="javascript" src="https://cdn.sheetjs.com/xlsx-0.18.9/package/dist/xlsx.mini.min.js"></script>
Internet Explorer and Older BrowsersInternet Explorer和旧浏览器
For broad compatibility with JavaScript engines, the library is written using ECMAScript 3 language dialect. 为了与JavaScript引擎广泛兼容,该库使用ECMAScript 3语言方言编写。A "shim" script provides implementations of functions for older browsers and environments.“垫片”脚本为较旧的浏览器和环境提供了功能实现。
Add a 在加载script
reference to the shim before the script tag that loads xlsx.js
:xlsx.js
的脚本标记之前,向填充程序添加script
引用:
<!-- add the shim first -->
<script type="text/javascript" src="shim.min.js"></script>
<!-- after the shim is referenced, add the library -->
<script type="text/javascript" src="xlsx.full.min.js"></script>
Web Workers
The standalone scripts can be loaded using 可以使用辅助脚本顶部的importScripts
at the top of the worker scripts:importScripts
加载独立脚本:
importScripts("https://cdn.sheetjs.com/xlsx-0.18.9/package/dist/shim.min.js");
importScripts("https://cdn.sheetjs.com/xlsx-0.18.9/package/dist/xlsx.full.min.js");
ECMAScript Module Imports in a SCRIPT TAGECMAScript模块在脚本标记中导入
caution
This section refers to imports using 本节介绍使用script type="module"
. script type="module"
的导入。For imports in modern projects using Webpack or React or Angular or Vue, the installation is described in the next section.对于使用Webpack或React或Angular或Vue的现代项目中的导入,安装将在下一节中介绍。
The ECMAScript Module build is saved to ECMAScript模块构建保存到xlsx.mjs
and can be directly added to a page with a script
tag using type="module"
:xlsx.mjs
,可以使用type="module"
直接添加到带有脚本script
的页面:
<script type="module">
import { read, writeFileXLSX } from "https://cdn.sheetjs.com/xlsx-0.18.9/package/xlsx.mjs";
</script>
If XLS support is required, 如果需要XLS支持,则必须手动导入cpexcel.full.mjs
must be manually imported:cpexcel.full.mjs
:
<script type="module">
/* load the codepage support library for extended support with older formats */
import { set_cptable } from "https://cdn.sheetjs.com/xlsx-0.18.9/package/xlsx.mjs";
import * as cptable from 'https://cdn.sheetjs.com/xlsx-0.18.9/package/dist/cpexcel.full.mjs';
set_cptable(cptable);
</script>
Dynamic imports with 可以在数据导出场景中使用带有import()
can be used in data export scenarios. import()
的动态导入。This example will download the library only when the export button is pressed:此示例仅在按下导出按钮时下载库:
<button id="xport">Export</button>
<script type="module">
xport.addEventListener("click", async() => {
/* dynamically import the library in the event listener */
const XLSX = await import("https://cdn.sheetjs.com/xlsx-0.18.9/package/xlsx.mjs");
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.aoa_to_sheet([["a","b","c"],[1,2,3]]);
XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
XLSX.writeFile(wb, "SheetJSESMTest.xlsx");
});
</script>
Bower
caution
Bower is deprecated and the maintainers recommend using other tools.Bower已被弃用,维护人员建议使用其他工具。
Bower plays nice with the CDN tarballs:很好地使用CDN tarballs:
$ npx bower install https://cdn.sheetjs.com/xlsx-0.18.9/xlsx-0.18.9.tgz
Bower will place the standalone scripts in Bower将把独立脚本放在bower_components/js-xlsx/dist/
bower_components/js-xlsx/dist/
中。