Skip to content

add sheetjs adaptor - #1790

Open
mtuchi wants to merge 8 commits into
mainfrom
sheetjs-adaptor
Open

mtuchi wants to merge 8 commits into
mainfrom
sheetjs-adaptor

Conversation

@mtuchi

@mtuchi mtuchi commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Add a sheetjs adaptor for excel transformation

Fixes #1718

Details

Added the following functions

  • jsonToSheet, Build a spreadsheet file from an array of objects
  • sheetToCsv, Convert a worksheet into a CSV string
  • sheetToJson, Convert a worksheet into an array of objects,
  • parse, Parse spreadsheet file content into a workbook.
  • xlsx, To use all xlsx utils functions

AI Usage

Please disclose how you've used AI in this work (it's cool, we just want to
know!):

  • I have used Claude Code
  • I have used another model
  • I have not used AI

You can read more details in our
Responsible AI Policy

Review Checklist

Before merging, the reviewer should check the following items:

  • Does the PR do what it claims to do?
  • If this is a new adaptor, added the adaptor on marketing website ?
  • If this PR includes breaking changes, do we need to update any jobs in
    production? Is it safe to release?
  • Are there any unit tests?
  • Is there a changeset associated with this PR? Should there be? Note that
    dev only changes don't need a changeset.
  • If there is a changeset, was pnpm run version used to bump versions (not
    pnpm changeset version directly)? This ensures changelog dates are stamped correctly.
  • Have you ticked a box under AI Usage?

@hunterachieng hunterachieng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A single-column CSV can be silently misread as base64 and return an empty array with no error. Example: sheetToJson("name\nJohn\nJane") returns []. The stripped content "nameJohnJane" (12 chars) passes the base64 round-trip check, so it's decoded as binary garbage instead of text. This is data-dependent ("id\n1234\n5678" works fine), so it'll pass in testing and corrupt real files in production. The JSDoc at Adaptor.js:94 acknowledges the ambiguity but there's no guard and no test. Can we bias detection toward text when the content contains newlines, and add a regression test?

Comment thread packages/sheetjs/src/Utils.js Outdated
Comment thread packages/sheetjs/src/Utils.js Outdated
Comment thread packages/sheetjs/src/Utils.js Outdated
Comment thread packages/sheetjs/src/Utils.js
Comment thread packages/sheetjs/src/Utils.js
Comment thread packages/sheetjs/test/helpers.js
mtuchi and others added 6 commits October 1, 2026 18:03
Operations previously accepted `null` to reuse a workbook cached in a
module-level closure. That made the data flow implicit, and reserved a
positional argument for "look at hidden state".

Each of parse, sheetToJson and sheetToCsv now takes the file content and
parses it, so jobs reference the file from state as usual:

  sheetToJson($.data.fileContent, { sheetName: 'Orders' })

A parsed workbook is deliberately never written to state. expandReferences
rebuilds objects from their own keys, and a Date has none, so a workbook
routed through state comes back with every date nulled. Buffers and strings
pass through untouched, so content is safe to reference with `$.`.

The trade is that reading several sheets from one file parses it several
times - roughly 470ms per call on a 10MB file, a few ms on a typical one.

Also removes the setWorkbook test seam (and its build warning), tightens the
JSDoc descriptions that become the public docs, and reworks the date
regression test around a lazy state reference.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
- Export the full SheetJS library as `xlsx` for use in job code, and
  document it in the README
- Restrict file content to a Buffer or a string (base64, base64 data URL
  or raw csv text). Uint8Array/ArrayBuffer never worked, since
  expandReferences walks them as plain objects, so drop them from the
  docs and throw an error suggesting Buffer.from() instead
- Test that a Uint8Array is rejected with that hint

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Pass dateNF to xlsx.read in sheetToJson and sheetToCsv. SheetJS
  formats cell text at read time and sheet_to_csv/sheet_to_json ignore
  dateNF for cells that already have text, so the option had no effect
- Move the cellDates: false example from parse to sheetToJson, where it
  changes the output, and document cellDates on SheetToJsonOptions
- Reject a data URL with no comma, and validate base64 with
  decodeBase64 before falling back to a plain decode
- Test sheetToCsv RS, strip, blankrows, rawNumbers and dateNF;
  sheetToJson cellDates and dateNF; parse with cellDates: false; and
  jsonToSheet with output: 'base64' and bookType: 'csv'
- Remove redundant comments

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@mtuchi

mtuchi commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

Hey @hunterachieng i have addressed your feedback can you take a look again

@hunterachieng hunterachieng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@mtuchi I think some comments were missed. Do you mind checking those out?

Comment thread packages/sheetjs/src/Utils.js
Comment thread packages/sheetjs/src/Utils.js
Comment thread packages/sheetjs/src/Utils.js Outdated
Comment thread packages/sheetjs/src/Utils.js Outdated
mtuchi and others added 2 commits October 12, 2026 16:36
Rename describe to describeType and handle undefined items, simplify
isWrappedLikeBase64, and assert exact error messages in tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@mtuchi
mtuchi requested a review from hunterachieng October 12, 2026 13:51
@mtuchi

mtuchi commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

Hey @hunterachieng can you give this another round of review ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

add a sheetjs adaptor

4 participants