0.3.0 ā€¢ Published 4 years ago

node-xml-xlsx v0.3.0

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

node-xml-xlsx

šŸ“‹ XLSX file generator for NodeJS

Installation

npm i node-xml-xlsx

Usage

const fs = require('fs');
const Xlsx = require('node-xml-xlsx');

const xlsx = new Xlsx();
const xlsxFileStream = xlsx.getStream();

// Pipe xlsx file to a writeable stream
xlsxFileStream.pipe(fs.createWriteStream('./new-workbook.xlsx'));

// Append rows to the Xlsx file
xlsx.addRow([
	'id',
	'first name',
	'last name',
	'age',
	'country',
	'date'
]);

xlsx.addRow([
	1,
	'John',
	'Appleseed',
	42,
	'EE.UU.',
]);

// Invoke build to finalize workbook writting
xlsx.build();

API

Xlsx

Creates an instance of Xlsx object in order to write a new XLSX workbook.

const Xlsx = require('node-xml-xlsx');

const xlsx = new Xlsx();

Xlsx.getStream(): Archiver

node-xml-xlsx uses Archiver internally to create a zip file. An xlsx file is basically a zip file with an specific structure based on xml files.

Returns an Archiver instance that can be used to pipe the file contents to a writeable stream while writting the xlsx file.

const fs = require('fs');
const Xlsx = require('node-xml-xlsx');

const xlsx = new Xlsx();
const xlsxFileStream = xlsx.getStream();

xlsxFileStream.pipe(fs.createWriteStream('./workbook.xlsx'));

Xlsx.addRow(values: XLSXValue[]): void

Appends a new row to the xlsx file based on the array values. Each element of the array represents a column of the xlsx file.

// Append rows to the Xlsx file
xlsx.addRow([
	'id',
	'first name',
	'last name',
	'age',
	'country',
	'date'
]);

xlsx.addRow([
	1,
	'John',
	'Appleseed',
	42,
	'EE.UU.',
]);

Xlsx.build(): Promise

Finalizes writting process and write footters to the zip file.

// Invoke build to finish workbook writting
xlsx.build();

Sheet

A Sheet implements the capabilities of an xlsx file's sheet.

Sheet's API is exported but its usage is internal, in the current version node-xml-xlsx is capable of creating single sheet workbooks only.

Sheet - XLSXValue

Sheet's type XLSXValue enumerates available types to be written in a sheet.

The current types are:

  • String
  • Number

Support for more types could be added further based on Issues/Requests.

Contributions

Any contribution is welcome, feel free to open either a pull request or issue (also both), and remember to write out your name, email and website in the Authors file.

License

Licensed under the MIT License

0.3.0

4 years ago

0.2.1

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.1.0-beta2

5 years ago

0.1.0-beta1

5 years ago

0.1.0-beta

5 years ago