Skip to content
This repository has been archived by the owner on Sep 28, 2020. It is now read-only.

EstebanBorai/node-xml-xlsx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

47 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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