Util to generate compatible Excel/OpenOffice/... XLS file (xml in fact). Works with node (typescript and javascript) and browser (using a html script tag). CommonJS and ES6 module compatible. No dependencies.
Works with your favorite frameworks and libraries (Angular, React, Electron, Webpack...) and in the browser using the script tag.
Compatible with all browsers (IE9+ included).
This util comes as npm package to be imported/required in your project or as standalone javascript file to be used directly in the HTML file (runs directly on the browser).
To install the module:
npm install --save to-excel
or
yarn install --save to-excel
To install the script:
The script is published as a Release in Github. You can download and include in your project or use it directly from github as CDN.
CDN (using latest version):
https://github.com/m0rtadelo/to-excel/releases/latest/download/to-excel.js
CDN (using 2.2.4 version):
https://github.com/m0rtadelo/to-excel/releases/download/2.2.4/to-excel.js
// include library (only one of the above methods)
<script src="https://github.com/m0rtadelo/to-excel/releases/latest/download/to-excel.js"></script> // HTML
var toExcel = require('to-excel').toExcel; // CommonJS
import { toExcel } from 'to-excel'; // ES6
// set data
var data = [
{ id: 1, value: 'Item 1 <br>', status: { item: '가지마' } },
{ value: 'Item 2', status: { item: 'благодарю вас' } },
{ value: 'Item 3 \'quotes\'', id: 3, status: { item: 'Enabled' } },
{ id: 4, value: 'Item 4 "quotes"', extra: 'ignored field' }
];
// set headers
var headers = [
{ label: 'Identificator', field: 'id' },
{ label: 'Description', field: 'value' },
{ label: 'Status', field: 'status.item' }
]
// set replacement values (optional)
toExcel.setReplace('Item 1 <br>', 'Item 1')
// generate excel file (will download 'filename.xls' from browser)
var content = toExcel.exportXLS( headers, data, 'filename' );
// in node you must open or save the content
require('fs').writeFileSync('filename.xls', content);
Demo available at: https://m0rtadelo.github.io/to-excel/demo/
The entry function exportXLS(headers, data, options)
will allow the next parameters:
This object defines column labels and maps worksheet data.
The next optional settings can be passed to exportXLS
function to change defaut behaviors:
this option keys must be passed into an object but, if string is detected
filename
will be used to store it.
Full documentation available at: https://m0rtadelo.github.io/to-excel/
Generated using TypeDoc