Skip to content

apify/xlsx-stream

Repository files navigation

XLSX Write Stream library

Build Status npm version

XLSX Write Stream is a streaming writer for XLSX spreadsheets. Its purpose is to replace CSV for large exports, because using CSV in Excel is very buggy and error prone. It's very efficient and can quickly write hundreds of thousands of rows with low memory usage.

XLSX Write Stream does not support formatting, charts, comments and a myriad of other OOXML features. It's strictly an CSV replacement.

Installation

npm i 'xlsx-write-stream'

Example Usage

import XLSXTransformStream from 'xlsx-write-stream';

// Input stream needs to implement Stream.Readable interface
// and each chunk should be an array of values (only string, date and number are supported value types)
inputStream
    .pipe(new XLSXTransformStream()) // This stream transforms the input into a xlsx format
    .pipe(fs.createWriteStream('file.xlsx')); // We need to store the result somewhere

Internals documentation

A .xlsx file is a ZIP archive with a standardized structure. The main class (XLSXTransformStream) creates this archive by first adding a few static metadata files, and then streams the actual content of the sheet into a sheet1.xml entry. The resulting ZIP stream becomes the output of XLSXTransformStream.

See the diagram below for a visual overview:

                      [ * ] (Start)
                        |
                        | Dataset rows
                        v
                +---------------------------+      Output bytes
                |    XLSXTransformStream    |----------------------> [*] (End)
                +---------------------------+
                  |               |      ^
     Dataset rows |         Other |      | ZIP.on("data", (bytes)
                  |         files |      |   => this.push(bytes))
                  v               v      |
        +------------------+  +------------------+
        | XLSXRowTransform |  |                  |
        +------------------+  |                  |
                  |           |                  |
             Text |           |     ZIP file     |
                  v           |                  |
        +------------------+  |                  |
        |   sheet1.xml     |  |                  |
        |   ZIP entry      |  |                  |
        +------------------+  +------------------+
                  |                   ^
                  |   Is included in  |
                  +-------------------+

License

This package is available as open source under the terms of the MIT License.

About

JavaScript / Node.js library to stream data into an XLSX file

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors