/meteor-excel

Primary LanguageJavaScript

meteor-excel

Mainly this package is a wrap for the npm packages listed above. So checkout their documentation to see how to work with excel files properly.

Parsing and generating excel files (xlsx, xls).

This package uses the npm packages:

Getting Started

There is nothing like a good example to get started with this package. Check out this MeteorPad for an exportable leaderboard to excel file. Follow the comments in the meteorpad, mainly in the server/app.js file.

Three steps to use it (basic cover)

1.- GET YOU APP PATH..

var fs = Npm.require('fs');
var path = Npm.require('path');
var basepath = path.resolve('.').split('.meteor')[0];

2.- CREATE A NEW EXCEL OBJECT

___ This package exports the Excel object to the server. Meaning this package is currently available only to the server side.___

To work with excel files first create an Excel object matching the excel file type you want to handle: xlsx/xls. To do that just use:

var excel = new Excel('xls');

or

var excel = new Excel('xlsx');

3.- READING XLS/X

  • Read a file
var workbook = excel.readFile( basepath+'yourFilesFoler/someExcelFile.xls'); 
  • Get the SheetNames (this is important to use most of the functions)
var yourSheetsName = workbook.SheetNames;
  • Get a cell
console.log("Get the 1st Sheet Name (remember is an array): " + workbook.SheetNames[0]);
console.log("Get Some Cell from it: " + workbook.Sheets[yourSheetsName[0]][
'C37'].v);
  • Make a JSON out of your excel
var workbookJson = excel.utils.sheet_to_json(workbook.Sheets[yourSheetsName[0]]);
console.log("Get the length: " + workbookJson.length);
  • Make a CSV out of your excel
var workbookCsv = excel.utils.sheet_to_csv(workbook.Sheets[yourSheetsName[0]]);
console.log(workbookCsv.length);

Contribute

Used this package? got an example to show? conact me or PR the README and i'll happly add it :)