Skip to content

add a sheetjs adaptor #1718

Open
Open

Description

@mtuchi

Request

We want to build a sheetjs utility adaptor that wraps the SheetJS (xlsx) library to make it easy to work with Excel and other spreadsheet files inside OpenFn jobs.

Unlike most adaptors, this is not an HTTP client for an external API. It's a data-transformation utility adaptor (similar in spirit to common) that operates on spreadsheet content already available on state (e.g., a base64 string or buffer fetched by another adaptor, a webhook payload).

To start, this adaptor should:

  1. Parse .xlsx/.xls/.csv file content (buffer or base64 string) into a SheetJS workbook and expose the sheet names.
  2. Convert a worksheet into an array of JSON objects (XLSX.utils.sheet_to_json), with options for header rows, ranges, raw values, and date handling.
  3. Convert a worksheet into a CSV string (XLSX.utils.sheet_to_csv).
  4. Go the other way: build a worksheet/workbook from JSON data (XLSX.utils.json_to_sheet, XLSX.write) and output it as a buffer or base64 string so downstream steps (e.g., http, sftp, googledrive) can upload or send the file.

Implementation note: SheetJS no longer publishes current versions to the public npm registry. The dependency must be installed from the official SheetJS CDN tarball:

https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz

i.e., in package.json:

"dependencies": {
  "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
}

Sample Code

// Parse an xlsx file (base64 from a previous step) into JSON rows
parse($.data.fileContent, { type: 'base64' });

// Convert a specific sheet to an array of JSON objects
sheetToJson($.workbook, { sheetName: 'Sheet1', header: 1, raw: false });

// Convert a sheet to a CSV string
sheetToCsv($.workbook, { sheetName: 'Orders' });

// Build an xlsx file from JSON records and return it as base64 for upload
jsonToSheet($.data.records, {
  sheetName: 'Export',
  output: 'base64',
});

(Function names/signatures to be finalized during design; these illustrate the intended developer experience.)

Important

Activity

  1. self-assigned this
    on Jul 8, 2026
  2. josephjclark commented on Jul 9, 2026

    @josephjclark
    Collaborator

    I would also export the xlsx object a global. So you can do:

    fn((state) =>  { 
       state.sheet = xlsx.sheetToJson(state.workbook, { sheetName: 'Sheet1', header: 1, raw: false });
       return state
    })
    

    That exposes all the functionality of the sheetjs to users, but gives us convenience wrappers for the most common steps

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

Metadata

Metadata

Assignees

Labels

P3Priority Level

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions