sheetjs/demos/angular2
Austin Turner d443860e6d Improved Code Style of Angular 2+ Demo [ci skip] 2017-08-05 18:23:11 -06:00
..
src Improved Code Style of Angular 2+ Demo [ci skip] 2017-08-05 18:23:11 -06:00
.angular-cli.json angular 2 / angular 4 demo [ci skip] 2017-06-21 19:10:36 -04:00
.gitignore version bump 0.10.8 2017-07-10 18:18:18 -04:00
Makefile hodgepodge of fixes 2017-07-27 17:15:55 -04:00
README.md angular 2 / angular 4 demo [ci skip] 2017-06-21 19:10:36 -04:00
package.json hodgepodge of fixes 2017-07-27 17:15:55 -04:00
package.json-angular2 angular 2 / angular 4 demo [ci skip] 2017-06-21 19:10:36 -04:00
package.json-angular4 angular 2 / angular 4 demo [ci skip] 2017-06-21 19:10:36 -04:00
tsconfig.json angular 2 / angular 4 demo [ci skip] 2017-06-21 19:10:36 -04:00

Angular 2+

The library can be imported directly from TS code with:

import * as XLSX from 'xlsx';

This demo uses an array of arrays as the core data structure. The component template includes a file input element, a table that updates based on the data, and a button to export the data.

Switching between Angular versions

Modules that work with Angular 2 largely work as-is with Angular 4. Switching between versions is mostly a matter of installing the correct version of the core and associated modules. This demo includes a package.json for Angular 2 and another package.json for Angular 4.

Switching to Angular 2 is as simple as:

$ cp package.json-angular2 package.json
$ npm install
$ ng serve

Switching to Angular 4 is as simple as:

$ cp package.json-angular4 package.json
$ npm install
$ ng serve

In this tree, node_modules/xlsx is a symlink pointing back to the root. This enables testing the development version of the library. In order to use this demo in other applications, add the xlsx dependency:

$ npm install --save xlsx

SystemJS Configuration

The default angular-cli configuration requires no additional configuration.

Some deployments use the SystemJS loader, which does require configuration. The SystemJS example shows the required meta and map settings:

SystemJS.config({
	meta: {
		'xlsx': {
			exports: 'XLSX' // <-- tell SystemJS to expose the XLSX variable
		}
	},
	map: {
		'xlsx': 'xlsx.full.min.js', // <-- make sure xlsx.full.min.js is in same dir
		'fs': '',     // <--|
		'crypto': '', // <--| suppress native node modules
		'stream': ''  // <--|
	}
});