# @atomictech/xlsx-write-stream 中文文档

规范地址：https://npmcn.com/package/%40atomictech/xlsx-write-stream/

版本：2\.0\.2
npm 元数据更新时间：2022-04-04T16:15:17.693Z
中文译文更新时间：2026-11-07T03:33:47.853Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40atomictech/xlsx-write-stream
原文对照：https://npmcn.com/package/%40atomictech/xlsx-write-stream/?lang=original
项目主页：https://github.com/atomictech/xlsx-write-stream
源码仓库：https://github.com/atomictech/xlsx-write-stream

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：85 kB，17 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：未声明
- 运行依赖：3 个
- 首次发布：2020-03-23T18:32:00.641Z
- 最新版本发布：2021-06-26T11:40:11.347Z
- 近 30 天下载量：11983（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：8（近 12 个月 0 个）

## 中文简介

将大量数据流流到XLSX生成的文件流中,最小的内存足迹.

## 安装

```sh
npm install @atomictech/xlsx-write-stream
```

也可以使用：`pnpm add @atomictech/xlsx-write-stream`、`yarn add @atomictech/xlsx-write-stream`、`bun add @atomictech/xlsx-write-stream`

## README

# XLSX 写流

[![Build Status](https://travis-ci.org/atomictech/xlsx-write-stream.svg)](https://travis-ci.org/atomictech/xlsx-write-stream) [![Version](https://img.shields.io/npm/v/@atomictech/xlsx-write-stream.svg)](https://www.npmjs.com/package/@atomictech/xlsx-write-stream) [![Documentation](https://img.shields.io/badge/documentation-yes-brightgreen.svg)](https://github.com/atomictech/xlsx-write-stream#readme) [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/atomictech/xlsx-write-stream/graphs/commit-activity) [![License: Apache-2.0](https://img.shields.io/github/license/atomictech/xlsx-write-stream)](https://github.com/atomictech/xlsx-write-stream/blob/master/LICENSE)

> 将大量数据流流到XLSX生成的文件流中,最小的内存足迹.

XLSX Write Stream是XLSX电子表格的流媒体写作机. 其宗旨是用CSV来取代大宗出口,因为Excel中使用CSV非常出错和容易出错. 它非常高效,可以快速地以低内存用量来写出数十万行.

## 目录

-   [XLSX 写流](https://npmcn.com/package/%40atomictech/xlsx-write-stream/#readme--xlsx-write-stream-)
    -   [目录](https://npmcn.com/package/%40atomictech/xlsx-write-stream/#readme-table-of-content)
    -   [QQ 安装](https://npmcn.com/package/%40atomictech/xlsx-write-stream/#readme--install)
    -   [使用量](https://npmcn.com/package/%40atomictech/xlsx-write-stream/#readme--usage)
        -   [基本管道](https://npmcn.com/package/%40atomictech/xlsx-write-stream/#readme-basic-pipe)
        -   [基本写法](https://npmcn.com/package/%40atomictech/xlsx-write-stream/#readme-basic-write)
        -   [自定义样式](https://npmcn.com/package/%40atomictech/xlsx-write-stream/#readme-custom-styles)
    -   [• API](https://npmcn.com/package/%40atomictech/xlsx-write-stream/#readme--api)
        -   [XLSX Write 结构化 `Transform`](https://npmcn.com/package/%40atomictech/xlsx-write-stream/#readme-xlsxwritestream--transform)
        -   [新建 XLSXWrite 结构( \[选项\])](https://npmcn.com/package/%40atomictech/xlsx-write-stream/#readme-new-xlsxwritestreamoptions)
        -   [样式](https://npmcn.com/package/%40atomictech/xlsx-write-stream/#readme-styledefs)
    -   [兼容性](https://npmcn.com/package/%40atomictech/xlsx-write-stream/#readme--compatibility)
    -   [作者数](https://npmcn.com/package/%40atomictech/xlsx-write-stream/#readme--authors)
    -   [捐款](https://npmcn.com/package/%40atomictech/xlsx-write-stream/#readme--contributing)
    -   [QQ 显示支持](https://npmcn.com/package/%40atomictech/xlsx-write-stream/#readme-%EF%B8%8F-show-your-support)
    -   [许可证](https://npmcn.com/package/%40atomictech/xlsx-write-stream/#readme--license)

## QQ 安装

```sh
npm install @atomictech/xlsx-write-stream
```

## 使用量

所有用法都记住,你应该养活自己 `XLSXWriteStream` 实例,其中一行可以是数组或对象.

```js
const row = [1, '02', new Date('2015-10-21T16:29:00.000Z'), true, false, '🦄'];
```

或者说

```js
const row = {
  'A Number Column': 1,
  'A Text Column': '02',
  'A Date Column': new Date('2015-10-21T16:29:00.000Z'),
  'A Boolean Column': true,
  'Another Boolean Column': false,
  'Another Text Column': '🦄'
};
```

### 基本管道

```js
import XLSXWriteStream from '@atomictech/xlsx-write-stream';

// Initialize the writer
const xlsxWriter = new XLSXWriteStream();

// Pipe a Stream.Readable input stream into the writer
const inputStream = new MyCustomReadableStream();
inputStream.pipe(xlsxWriter);

// Pipe the writer into a Stream.Writable output stream in order to retrieve XLSX file data,
// write it into file or send it as HTTP response.
const writeStream = fs.createWriteStream('file.xlsx');
xlsxWriter.pipe(writeStream);
```

### 基本写法

```js
import XLSXWriteStream from '@atomictech/xlsx-write-stream';

// [optional] Define some header
const columns = ['A Number Column', 'A Text Column', 'A Date Column', 'A Boolean Column', 'Another Boolean Column', 'Another Text Column'];

// Initialize the writer
const xlsxWriter = new XLSXWriteStream({ header: true, columns });

// Pipe the writer into a Stream.Writable output stream in order to retrieve XLSX file data,
// write it into file or send it as HTTP response.
const writeStream = fs.createWriteStream('file.xlsx');
xlsxWriter.pipe(writeStream);

// Write rows one by one with
const row = [1, '02', new Date('2015-10-21T16:29:00.000Z'), true, false, '🦄'];
xlsxWriter.write(row);
xlsxWriter.end(); // Do not forget to end the stream!
```

⚠️ **谨慎** ⚠️

如果您不熟悉溪流,为了利用这个表单可能最小的内存足迹,您需要意识到后压概念,并使用由写入函数返回的布尔!

> 见以下解释: [可写.write (chunk \[, 编码 \[, 调回\])](https://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback)

### 自定义样式

一个 `options.styleDefs` 参数可以重新定义类型样式格式.

```js
import { TypeStyleKey } from '@atomictech/xlsx-write-stream';

// Declare custom styles definitions
const styleDefs = {};
styleDefs[TypeStyleKey.DATE] = { formatCode: 'yy-mm-dd hh:mm' };
styleDefs[TypeStyleKey.INT] = { numFmtId: 49 }; // 49 is "enforced text format"

// Create the writer
const xlsxWriter = new XLSXWriterStream({ styleDefs });

// NB: if you set `format: false` your styleDefs will not be used
```

## • API

### XLSX Write 结构化 `Transform`

### 新建 XLSXWrite 结构( \[选项\])

创建新流转换, 将矩阵或对象作为输入块处理 . 注意第一行块是更多行块的变换配置过程中的决定因素.

| 参数 | 类型 | 默认 | 说明 |
| --- | --- | --- | --- |
| \[可选 | `Object` |  |  |
| \[选项.头 | `Boolean` | `false` | 如果提供或发现列选项,则在一行显示列名. |
| \[选项.列\] | `Array|Object` |  | 作为对象提供记录时的属性列表。 基于索引位置的数组形式的记录;顺序事项。 在第一个记录中发现的自动,当用户写入对象时,可以指输入JSON的嵌入属性,参见: `header` 选项,用于打印第一行的列名. |
| \[选项.format\] | `Boolean` | `true` | 如果设置为假写器, 则不会将单元格格式化为数字、 日期、 布尔和文本 . |
| \[选项.styleDefs\] | [`StyleDefs`](https://npmcn.com/package/%40atomictech/xlsx-write-stream/#readme-styledefs) |  | 如果设定了, 您可以用其它标准样式覆盖默认的标准类型样式, 甚至定义自定义 `formatCode`。 。 。 . |
| \[选项.即刻\] | `Boolean` | `false` | 如果设定为真写器, 将初始化归档并立即开始压缩 xlsx 常见内容, 并随后添加一些内存和处理器脚印 。 否则,初始化将推迟到第一次数据处理. |

### 样式

用于解释 StyleDefs 界面的一点类型脚本 :

```ts
enum TypeStyleKey = {
  NUMBER: 'default', //!\\ Unused in the actual type conversion
  INT: 'int', // Integer <1000
  FLOAT: 'float', // Float <1000
  BIG_INT: 'bigInt', // Integer >=1000
  BIG_FLOAT: 'bigFloat', // Float >=1000
  EXP_NUMBER: 'expNumber', // Number with more than 10 digits/characters (ex: 10000000000 or 12.45678901)
  TEXT: 'text', // String
  DATE: 'date', // Date
  DATETIME: 'datetime' //!\\ Unused in the actual type conversion
};

interface TypeFormatReference {
  numFmtId: number;
}

interface TypeFormatDefinition {
  formatCode: string;
}

interface StyleDefs {
    [typeKey: TypeStyleKey]: TypeFormatReference | TypeFormatDefinition;
}
```

示例

```js
{
  date: { formatCode: 'yy-mm-dd hh:mm' },
  int: { numFmt: 49 }
}
```

> 其他默认数字FmtId请参见此 : [https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.numberingformat?view=openxml-2.8.1 页面存档备份,存于互联网档案馆](https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.numberingformat?view=openxml-2.8.1)

## 兼容性

XLSX 写入流 - 支持 :

单元格类型 :

-   字符串 \[开始于 `=`\[ 公式
-   字符串 \[其他\] qq文本
-   日期 + 日期
-   编号 编号
-   布尔 qq 布尔

单元格类型格式 :

-   文本( 默认 ): `numFmtId: 49` - 执行案文,即使可以解释为数目)
-   日期( 默认 ): `formatCode: 'yyyy-mm-dd'` - ) - 说吧
-   编号
    -   int( 默认 ): `numFmtId: 1`(中文(简体) )
    -   浮点( 默认 ): `numFmtId: 2`(中文(简体) )
    -   bigInt( 默认 ): `numFmtId: 3`(中文(简体) )
    -   大浮点数( 默认 ): `numFmtId: 4`(中文(简体) )
    -   exp 编号( 默认 ): `numFmtId: 1`(中文(简体) )

XLSX 写入流 - **没有** 支持:

-   图表
-   评论
-   ...和众多其他OOXML特性. 严格来说是CSV替换.

## 作者数

👤 **说明**

-   网站: [https://apify.com/ (中文(简体) )](https://apify.com/)
-   吉图布: [@ apifytech (帮助)](https://github.com/apifytech)

👤 **原子技术**

-   吉图布: [@ 原子技术](https://github.com/atomictech)

## 捐款

欢迎发言、问题和特稿请求!  
随便你看看 [问题页面](https://github.com/atomictech/xlsx-write-stream/issues)。您还可以查看 [贡献指南](https://github.com/atomictech/xlsx-write-stream/blob/master/CONTRIBUTING.md)。 。 。 .

## QQ 显示支持

如果这个计划能帮助你的话,就给你一个!

## 许可证

这个项目是 [阿帕奇 - 2.0](https://github.com/atomictech/xlsx-write-stream/blob/master/LICENSE) 有执照.

## 常见问题

### @atomictech/xlsx-write-stream 是什么？

将大量数据流流到XLSX生成的文件流中,最小的内存足迹\.

### 如何安装 @atomictech/xlsx-write-stream？

在项目目录运行 npm install @atomictech/xlsx-write-stream，或使用 pnpm add / yarn add / bun add。

### @atomictech/xlsx-write-stream 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/atomictech\_\_xlsx-write-stream 是否存在。

### @atomictech/xlsx-write-stream 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @atomictech/xlsx-write-stream 可以商用吗？

@atomictech/xlsx-write-stream 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @atomictech/xlsx-write-stream 的下载量有多少？

根据 npm 官方下载统计，@atomictech/xlsx-write-stream 在 2026/10/07 – 2026/11/05 这 30 天内被下载 11,983 次，日均约 399 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @atomictech/xlsx-write-stream 还在维护吗？

最新版本 2\.0\.2 发布于 2021/06/26（5 年前）；至今共发布 8 个版本，其中过去 12 个月发布了 0 个；首次发布于 2020/03/24。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

