1.0.0 • Published 1 year ago

xlsx-table-data-to-json v1.0.0

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
1 year ago

XLSX Table Data to JSON

This package augments table-data-to-json with the ability to load and extract data from XLSX files using xlsx.

Thanks to the fully-featured nature of xlsx, this package supports CSV files out of the box as well.

Installation

  npm i xlsx-table-data-to-json
  yarn add xlsx-table-data-to-json

Usage

Import and use convertXLSXToJSON(options) within your project like so:

import convertXLSXToJSON from "xlsx-table-data-to-json";

// @NOTE: Unlike `table-data-to-json`, `xlsx-table-data-to-json` relies on
//        `async`, so will require `await` or `.then()`.
const jsonData = await convertXLSXToJSON(options);

Path to a local XLSX/CSV file can be given, or you can give it a Buffer directly:

const jsonData = await convertXLSXToJSON({
  file: path.join(__dirname, "example.xlsx"),
});

const jsonData = await convertXLSXToJSON({
  file: fs.readFileSync(path.join(__dirname, "example.xlsx")),
});

URL to a remote XLSX/CSV file can be provided as well:

const jsonData = await convertXLSXToJSON({
  url: "https://example.com/example.xlsx",
});

You can even give it an xlsx.WorkBook instance:

const jsonData = await convertXLSXToJSON({
  data: xlsxWorkBook,
});

Options

PropertyTypeDescription
options.fileString or BufferEither the path to a local file or a Buffer object itself.
options.urlStringURL to a remote file.
options.dataxlsx.WorkBookThe xlsx.WorkBook instance.
options.sheetIndexNumberA zero-index number which corresponds to the sheet you want to convert.
options.sheetNameStringThe name of the sheet you want to convert.
options.parsingOptionsxlsx.ParsingOptionsOverride or augment any further xlsx parsing options.
presetStringAccepted values:rowcolumnrow.columncolumn.rowrow.row
headersTableDataConfigHeadersIn case the presets don't cover your use-case, you can specify the headers here.

Development

To download external dependencies:

  npm i

To run tests (using Jest):

  npm test
  npm run test:watch

Contribute

Got cool ideas? Have questions or feedback? Found a bug? Post an issue

Added a feature? Fixed a bug? Post a PR

License

Apache 2.0