Skip to content

feat: support web-native streams for read/write methods#2849

Open
lionel-rowe wants to merge 3 commits into
exceljs:masterfrom
lionel-rowe:web-native-streams
Open

feat: support web-native streams for read/write methods#2849
lionel-rowe wants to merge 3 commits into
exceljs:masterfrom
lionel-rowe:web-native-streams

Conversation

@lionel-rowe

Copy link
Copy Markdown

Fixes #1228
Fixes #2753

Summary

Add support for read(<web-native ReadableStream instance>) and write(<web-native WritableStream instance>). Both have excellent support in modern browsers and are also implemented in NodeJS, Deno, and Bun.

Test plan

See spec/unit/xlsx/write-writable-stream.spec.js and changes to spec/typescript/exceljs.spec.ts.

Related to source code (for typings update)

N/A (updated typings are reflected in diffs to runtime code + tests).

import _ExcelJS from '../../index';
import type * as ExcelJSModule from '../../exceljs';

const ExcelJS = _ExcelJS as unknown as typeof ExcelJSModule;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type checking wasn't currently being picked up by ts-node due to ../../index resolving to the untyped index files rather than ../../index.d.ts.

https://stackoverflow.com/questions/62490423/consume-index-d-ts-declaration-file-in-source-code

It looks like you have a collision in your module resolution.

If you have a file called index.ts, then index.d.ts won't be automatically imported.

TypeScript will automatically import .d.ts files, UNLESS their name collides with other files, where the rules for what files will collide are somewhat described here: https://www.typescriptlang.org/docs/handbook/module-resolution.html .

For that reason, I've renamed index.d.ts to exceljs.d.ts (and updated the corresponding package.json fields etc).

It still needs to be imported in this weird way for the test though. Possibly there's a better fix, but I couldn't figure one out.

ws.getCell('A1').value = 7;

const wb2 = new ExcelJS.Workbook();
const stream = wb2.xlsx.createInputStream();

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was previously failing due to removal of createInputStream, so I've overwritten the existing test case rather than adding a new one.

Comment thread package.json
"test": "npm run test:full",
"test:es5": "export EXCEL_BUILD=es5 && npm run test:full",
"test:full": "npm run build && npm run test:unit && npm run test:integration && npm run test:end-to-end && npm run test:jasmine",
"test:full": "npm run build && npm run test:unit && npm run test:integration && npm run test:end-to-end && npm run test:jasmine && npm run test:typescript",

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added TS tests to test:full, which should now work as they no longer contain a failing test case.

privatecoder added a commit to privatecoder/exceljs that referenced this pull request Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Q] What's the status to support Web Stream ? Support Stream writing in browser

1 participant