Skip to main content

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写入filenameIn 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写入filenameIf o is omitted, the writer will use the third argument as the callback.如果省略了o,编写器将使用第三个参数作为回调。

The write functions accept an options argument:write函数接受options参数:

Option Name选项名称Default默认值Description描述
typeOutput data encoding (see Output Type below)输出数据编码(见下面的输出类型)
cellDatesfalseStore dates as type d (default is n)将日期存储为类型d(默认值为n
bookSSTfalseGenerate Shared String Table生成共享字符串表 **
bookType"xlsx"Type of Workbook (see below for supported formats)工作簿类型(有关支持的格式,请参阅下文)
sheet""Name of Worksheet for single-sheet formats单页格式的工作表名称 **
compressionfalseUse ZIP compression for ZIP-based formats对基于ZIP的格式使用ZIP压缩 **
PropsOverride workbook properties when writing写入时重写工作簿属性 **
themeXLSXOverride theme XML when writing XLSX/XLSB/XLSM写入XLSX/XLSB/XLSM时重写主题XML **
ignoreECtrueSuppress "number as text" errors抑制“数字为文本”错误 **
numbersPayload for NUMBERS export数字导出的有效负载 **
  • 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 type d so non-Excel tools may ignore the data or error in the presence of dates.Excel本身通常不会写入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 (to xl/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 to false 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 script加载xlsx.zahl脚本

2) Pass the payload into the numbers option to write or writeFile.将有效负载传递到numbers选项为writewriteFile

<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>

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选项控制:

bookTypefile ext文件扩展名container容器sheets工作表Description描述
xlsx.xlsxZIPmultiExcel 2007+ XML Format
xlsm.xlsmZIPmultiExcel 2007+ Macro XML Format
xlsb.xlsbZIPmultiExcel 2007+ Binary Format
biff8.xlsCFBmultiExcel 97-2004 Workbook Format
biff5.xlsCFBmultiExcel 5.0/95 Workbook Format
biff4.xlsnonesingleExcel 4.0 Worksheet Format
biff3.xlsnonesingleExcel 3.0 Worksheet Format
biff2.xlsnonesingleExcel 2.0 Worksheet Format
xlml.xlsnonemultiExcel 2003-2004 (SpreadsheetML)
numbers.numbersZIPsingleNumbers 3.0+ Spreadsheet
ods.odsZIPmultiOpenDocument Spreadsheet
fods.fodsnonemultiFlat OpenDocument Spreadsheet
wk3.wk3nonemultiLotus Workbook (WK3)
csv.csvnonesingleComma Separated Values
txt.txtnonesingleUTF-16 Unicode Text (TXT)
sylk.sylknonesingleSymbolic Link (SYLK)
html.htmlnonesingleHTML Document
dif.difnonesingleData Interchange Format (DIF)
dbf.dbfnonesingledBASE II + VFP Extensions (DBF)
wk1.wk1nonesingleLotus Worksheet (WK1)
rtf.rtfnonesingleRich Text Format (RTF)
prn.prnnonesingleLotus Formatted Text
eth.ethnonesingleEthercalc 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的类型参数:

typeoutput输出
"base64"string: Base64 encoding of the file字符串:文件的Base64编码
"binary"string: binary string (byte n is data.charCodeAt(n))字符串:二进制字符串(字节ndata.charCodeAt(n)
"string"string: JS string (characters interpreted as UTF8)字符串:JS string(解释为UTF8的字符)
"buffer"nodejs Buffer
"array"ArrayBuffer, fallback array of 8-bit unsigned intArrayBuffer,8位无符号int的回退数组
"file"string: path of file that will be created (nodejs only)字符串:将创建的文件路径(仅限Node.js)
  • For compatibility with Excel, csv output will always include the UTF-8 byte order mark.为了与Excel兼容,csv输出将始终包括UTF-8字节顺序标记。