sheetjs@1.0.1 
This adaptor exports the following namespaced functions:
This adaptor exports the following from common:
- as()
- combine()
- cursor()
- dataPath()
- dataValue()
- dateFns
- each()
- field()
- fields()
- fn()
- fnIf()
- group()
- lastReferenceValue()
- map()
- merge()
- scrubEmojis()
- sourceValue()
- util
- combine()
Functions
jsonToSheet
jsonToSheet(data, options) ⇒ Operation
Build a spreadsheet file from an array of objects.
Writes { buffer, bookType, sheetName } to state.data, or
{ base64, bookType, sheetName } with output: 'base64'.
Column headers come from the keys of the data. Pass header to fix their
order.
| Param | Type | Description |
|---|---|---|
| data | Array.<object> | An array of objects, one per row |
| options | JsonToSheetOptions | Optional write options |
This operation writes the following keys to state:
| State Key | Description |
|---|---|
| data | an object with the file as buffer (or base64 with output: 'base64'), plus bookType and sheetName |
Example: Build an xlsx buffer from records on state
jsonToSheet($.data.records, { sheetName: 'Export' });
Example: Build a base64 xlsx file, ready to upload
jsonToSheet($.data.records, { sheetName: 'Export', output: 'base64' });
Example: Write a CSV file with a fixed column order
jsonToSheet($.data.records, {
bookType: 'csv',
header: ['id', 'name', 'dateOfBirth'],
});
sheetToCsv
sheetToCsv(content, options) ⇒ Operation
Convert a worksheet into a CSV string and write it to state.data.
Reads the first sheet unless sheetName or sheetIndex says otherwise.
The content type is detected automatically. Pass type to override it.
| Param | Type | Description |
|---|---|---|
| content | FileContent | The file content to convert |
| options | SheetToCsvOptions | Optional conversion options |
This operation writes the following keys to state:
| State Key | Description |
|---|---|
| data | the CSV string |
Example: Convert an uploaded xlsx file straight to CSV
sheetToCsv($.data.fileContent);
Example: Convert a named sheet
sheetToCsv($.data.fileContent, { sheetName: 'Orders' });
Example: Use a semi-colon as the field separator
sheetToCsv($.data.fileContent, { FS: ';' });
sheetToJson
sheetToJson(content, options) ⇒ Operation
Convert a worksheet into an array of objects, one per row, and write it to
state.data.
Reads the first sheet unless sheetName or sheetIndex says otherwise.
The content type is detected automatically. Pass type to override it.
| Param | Type | Description |
|---|---|---|
| content | FileContent | The file content to convert |
| options | SheetToJsonOptions | Optional conversion options |
This operation writes the following keys to state:
| State Key | Description |
|---|---|
| data | an array of row objects, or arrays of cell values with header: 1 |
Example: Convert the first sheet of a file to JSON
sheetToJson($.data.fileContent);
Example: Convert a named sheet
sheetToJson($.data.fileContent, { sheetName: 'Orders' });
Example: Return dates as Date objects rather than Excel serial numbers
sheetToJson($.data.fileContent, { cellDates: true });
static
These functions belong to the static namespace.
static.exports
module.exports
The full SheetJS library, for
anything the operations above don't cover. Its functions are not
operations, so call them inside fn(), not at the top level of a job.
Example: Read a workbook and convert a named sheet yourself
fn(state => {
const workbook = xlsx.read(state.data.fileContent, { type: 'base64' });
state.rows = xlsx.utils.sheet_to_json(workbook.Sheets['Sheet1'], {
header: 1,
raw: false,
});
return state;
});
Interfaces
FileContent
File content to read. Accepts a Buffer, a base64 string, a base64 data URL, or the raw text of a CSV file.
JsonToSheetOptions
Options for building a spreadsheet file from JSON. Accepts any
SheetJS array of objects input option
and any SheetJS write option
except type - use output instead.
Properties
| Name | Type | Description |
|---|---|---|
| sheetName | string | Name of the worksheet. Default: 'Sheet1'. |
| output | 'buffer' | 'base64' | Return the file as a Buffer or a base64 string. Default: 'buffer'. |
SheetToCsvOptions
Options for converting a worksheet to CSV. Accepts any
SheetJS CSV output option
and any SheetJS parse option.
FS appears in both lists, and applies to the CSV output.
Properties
| Name | Type | Description |
|---|---|---|
| sheetName | string | Name of the sheet to convert. Defaults to the first sheet. |
| sheetIndex | number | Zero-based index of the sheet to convert. Ignored if sheetName is set. |
| rawNumbers | boolean | Write numbers as raw values rather than formatted text. |
SheetToJsonOptions
Options for converting a worksheet to JSON. Accepts any
SheetJS array output option
and any SheetJS parse option.
raw and UTC appear in both lists, and apply to the conversion.
Properties
| Name | Type | Description |
|---|---|---|
| sheetName | string | Name of the sheet to convert. Defaults to the first sheet. |
| sheetIndex | number | Zero-based index of the sheet to convert. Ignored if sheetName is set. |