Writing Options写入选项
XLSX.write(wb, write_opts)
attempts to write the workbook 尝试编写工作簿wb
XLSX.writeFile(wb, filename, write_opts)
attempts to write 尝试将wb
to filename
. wb
写入filename
。In browser-based environments, it will attempt to force a client-side download.在基于浏览器的环境中,它将尝试强制客户端下载。
XLSX.writeFileAsync(filename, wb, o, cb)
attempts to write 尝试将wb
to filename
. wb
写入filename
。If 如果省略了o
is omitted, the writer will use the third argument as the callback.o
,编写器将使用第三个参数作为回调。
The write functions accept an options argument:write函数接受options参数:
type | ||
cellDates | false | d (default is n )d (默认值为n ) |
bookSST | false | |
bookType | "xlsx" | |
sheet | "" | |
compression | false | |
Props | ||
themeXLSX | ||
ignoreEC | true | |
numbers |
bookSST
is slower and more memory intensive, but has better compatibility with older versions of iOS Numbers速度较慢,内存更密集,但与旧版本的iOS数字具有更好的兼容性The raw data is the only thing guaranteed to be saved.原始数据是唯一保证保存的数据。Features not described in this README may not be serialized.本自述文件中未描述的功能可能无法序列化。cellDates
only applies to XLSX output and is not guaranteed to work with third-party readers.仅适用于XLSX输出,不保证与第三方读卡器一起使用。Excel itself does not usually write cells with typeExcel本身通常不会写入d
so non-Excel tools may ignore the data or error in the presence of dates.d
类型的单元格,因此非Excel工具可能会忽略数据或存在日期的错误。Props
is an object mirroring the workbook是镜像工作簿Props
field.Props
字段的对象。See the table from the Workbook File Properties section.请参阅工作簿文件属性部分的表格。if specified, the string from如果指定,themeXLSX
will be saved as the primary theme for XLSX/XLSB/XLSM files (toxl/theme/theme1.xml
in the ZIP)themeXLSX
中的字符串将保存为XLSX/XLSB/XLSM文件的主主题(到ZIP中的xl/theme/theme1.xml
)Due to a bug in the program, some features like "Text to Columns" will crash Excel on worksheets where error conditions are ignored.由于程序中的错误,一些功能(如“文本到列”)将使Excel在忽略错误条件的工作表上崩溃。The writer will mark files to ignore the error by default.默认情况下,编写器会将文件标记为忽略错误。Set将ignoreEC
tofalse
to suppress.ignoreEC
设置为false
以抑制。
Exporting NUMBERS files导出数字文件 (click to show)
The NUMBERS writer requires a fairly large base. 数字编写器需要相当大的基数。The supplementary 补充的xlsx.zahl
scripts provide support. xlsx.zahl
脚本提供了支持。xlsx.zahl.js
is designed for standalone and NodeJS use, while xlsx.zahl.mjs
is suitable for ESM.xlsx.zahl.js
设计用于单机和Node.js,而xlsx.zahl.mjs
适用于ESM。
Adding NUMBERS export support involves two steps:添加数字导出支持包括两个步骤:
1) Load the 加载xlsx.zahl
scriptxlsx.zahl
脚本
2) Pass the payload into the 将有效负载传递到numbers
option to write
or writeFile
.numbers
选项为write
或writeFile
。
- Browser
- NodeJS
- Deno
<meta charset="utf8">
<body>
<script src="https://cdn.sheetjs.com/xlsx-0.18.9/package/dist/xlsx.full.min.js"></script>
<script src="https://cdn.sheetjs.com/xlsx-0.18.9/package/dist/xlsx.zahl.js"></script>
<script>
var wb = XLSX.utils.book_new(); var ws = XLSX.utils.aoa_to_sheet([
["SheetJS", "<3","விரிதாள்"],
[72,,"Arbeitsblätter"],
[,62,"数据"],
[true,false,],
]); XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
XLSX.writeFile(wb, "textport.numbers", {numbers: XLSX_ZAHL_PAYLOAD, compression: true});
</script>
</body>
After installing the package:安装软件包后:
$ npm install --save https://cdn.sheetjs.com/xlsx-0.18.9/xlsx-0.18.9.tgz
The scripts will be available at 脚本将在xlsx/dist/xlsx.zahl
(CommonJS) and xlsx/dist/xlsx.zahl.mjs
(ESM).xlsx/dist/xlsx.zahl
(CommonJS)和xlsx/dist/xlsx.zahl.mjs
(ESM)上提供。
var XLSX = require("xlsx");
var XLSX_ZAHL_PAYLOAD = require("xlsx/dist/xlsx.zahl");
var wb = XLSX.utils.book_new(); var ws = XLSX.utils.aoa_to_sheet([
["SheetJS", "<3","விரிதாள்"],
[72,,"Arbeitsblätter"],
[,62,"数据"],
[true,false,],
]); XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
XLSX.writeFile(wb, "textport.numbers", {numbers: XLSX_ZAHL_PAYLOAD, compression: true});
import * as XLSX from 'https://cdn.sheetjs.com/xlsx-0.18.9/package/xlsx.mjs';
import XLSX_ZAHL_PAYLOAD from 'https://cdn.sheetjs.com/xlsx-0.18.9/package/dist/xlsx.zahl.mjs';
var wb = XLSX.utils.book_new(); var ws = XLSX.utils.aoa_to_sheet([
["SheetJS", "<3","விரிதாள்"],
[72,,"Arbeitsblätter"],
[,62,"数据"],
[true,false,],
]); XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
XLSX.writeFile(wb, "textport.numbers", {numbers: XLSX_ZAHL_PAYLOAD, compression: true});
Supported Output Formats支持的输出格式
For broad compatibility with third-party tools, this library supports many output formats. 为了与第三方工具广泛兼容,该库支持多种输出格式。The specific file type is controlled with 具体文件类型由bookType
option:bookType
选项控制:
bookType | ||||
---|---|---|---|---|
xlsx | .xlsx | ZIP | multi | Excel 2007+ XML Format |
xlsm | .xlsm | ZIP | multi | Excel 2007+ Macro XML Format |
xlsb | .xlsb | ZIP | multi | Excel 2007+ Binary Format |
biff8 | .xls | CFB | multi | Excel 97-2004 Workbook Format |
biff5 | .xls | CFB | multi | Excel 5.0/95 Workbook Format |
biff4 | .xls | none | single | Excel 4.0 Worksheet Format |
biff3 | .xls | none | single | Excel 3.0 Worksheet Format |
biff2 | .xls | none | single | Excel 2.0 Worksheet Format |
xlml | .xls | none | multi | Excel 2003-2004 (SpreadsheetML) |
numbers | .numbers | ZIP | single | Numbers 3.0+ Spreadsheet |
ods | .ods | ZIP | multi | OpenDocument Spreadsheet |
fods | .fods | none | multi | Flat OpenDocument Spreadsheet |
wk3 | .wk3 | none | multi | Lotus Workbook (WK3) |
csv | .csv | none | single | Comma Separated Values |
txt | .txt | none | single | UTF-16 Unicode Text (TXT) |
sylk | .sylk | none | single | Symbolic Link (SYLK) |
html | .html | none | single | HTML Document |
dif | .dif | none | single | Data Interchange Format (DIF) |
dbf | .dbf | none | single | dBASE II + VFP Extensions (DBF) |
wk1 | .wk1 | none | single | Lotus Worksheet (WK1) |
rtf | .rtf | none | single | Rich Text Format (RTF) |
prn | .prn | none | single | Lotus Formatted Text |
eth | .eth | none | single | Ethercalc Record Format (ETH) |
compression
only applies to formats with ZIP containers.仅适用于带有ZIP容器的格式。Formats that only support a single sheet require a仅支持单个工作表的格式需要指定工作表的sheet
option specifying the worksheet.sheet
选项。If the string is empty, the first worksheet is used.如果字符串为空,则使用第一个工作表。writeFile
will automatically guess the output file format based on the file extension if如果未指定bookType
is not specified.bookType
,将根据文件扩展名自动猜测输出文件格式。It will choose the first format in the aforementioned table that matches the extension.它将在上述表格中选择与扩展名匹配的第一种格式。
Output Type
The type
argument for write
mirrors the type
argument for read
:write
的类型参数镜像了read
的类型参数:
type | |
---|---|
"base64" | |
"binary" | n is data.charCodeAt(n) )n 是data.charCodeAt(n) ) |
"string" | |
"buffer" | nodejs Buffer |
"array" | |
"file" |
For compatibility with Excel,为了与Excel兼容,csv
output will always include the UTF-8 byte order mark.csv
输出将始终包括UTF-8字节顺序标记。