Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

pushing to node as 'xlsjs'

  • Loading branch information...
commit b5307cb821dbe68cf1c71ae3ee1479f3d104990b 1 parent 1b22b65
@SheetJSDev SheetJSDev authored
Showing with 58 additions and 14 deletions.
  1. +1 −0  .gitignore
  2. +6 −2 README.md
  3. +9 −0 bin/xls2csv.njs
  4. +22 −0 package.json
  5. +20 −12 xls.js
View
1  .gitignore
@@ -0,0 +1 @@
+node_modules
View
8 README.md
@@ -8,14 +8,18 @@ This has been tested on some basic XLS files generated from Excel 2011 (using co
## Installation
-THERE ARE PLANS FOR AN NPM MODULE (you can just require a few files and magic happens) but someone is squatting `xls`: https://npmjs.org/package/xls
-
In the browser:
<script src="xlsconsts.js"></script>
<script src="cfb.js"></script>
<script src="xls.js"></script>
+In node:
+
+ require('xlsjs').readFile('file');
+
+The command-line utility `xls2csv` shows how to generate a CSV from an XLS.
+
## Usage
See http://niggler.github.com/js-xls/ for a browser example.
View
9 bin/xls2csv.njs
@@ -0,0 +1,9 @@
+#!/usr/bin/env node
+
+var XLS = require('../xls');
+var wb = XLS.readFile(process.argv[2] || 'Book1.xls');
+var target_sheet = process.argv[3] || '';
+if(target_sheet === '') target_sheet = wb.Directory[0];
+var ws = wb.Sheets[target_sheet];
+console.log(target_sheet);
+console.log(XLS.utils.make_csv(ws));
View
22 package.json
@@ -0,0 +1,22 @@
+{
+ "name": "xlsjs",
+ "version": "0.0.1",
+ "author": "Niggler",
+ "description": "(one day) a full-featured XLS parser and writer. For now, primitive parser",
+ "keywords": [
+ "xls", "office", "excel", "spreadsheet"
+ ],
+ "bin": {
+ "xls2csv": "./bin/xls2csv.njs"
+ },
+ "main": "./xls",
+ "dependencies": {
+ "buffers":""
+ },
+ "repository": {
+ "type":"git",
+ "url": "git://github.com/Niggler/js-xls.git"
+ },
+ "bugs": { "url": "https://github.com/Niggler/js-xls/issues" },
+ "engines": { "node": ">=0.8" }
+}
View
32 xls.js
@@ -2,8 +2,6 @@ if(typeof require !== 'undefined') {
var CFB= require('./cfb');
var vm = require('vm'), fs = require('fs');
vm.runInThisContext(fs.readFileSync(__dirname+'/xlsconsts.js'));
- var cfb = CFB.read(process.argv[2] || 'Book1.xls', {type:'file'});
- var target_sheet = process.argv[3] || '';
}
/* MS-OLEDS 2.3.8 CompObjStream TODO */
@@ -40,8 +38,9 @@ var CompObjP, SummaryP, WorkbookP;
function parse_formula(formula, range) {
range = range || {s:{c:0, r:0}};
var stack = [], e1, e2, type, c, sht;
+ if(!formula[0] || !formula[0][0]) return "";
formula[0].forEach(function(f) {
- //console.log("++",f)
+ //console.log("++",f, formula[0])
switch(f[0]) {
/* Control Tokens -- ignore */
case 'PtgAttrIf': case 'PtgAttrChoose': case 'PtgAttrGoto': break;
@@ -257,13 +256,22 @@ function get_formulae(ws) {
return cmds;
}
-if(typeof require !== 'undefined') {
- var wb = parse_xlscfb(cfb);
- //console.log(wb);
- if(target_sheet === '') target_sheet = wb.Directory[0];
- console.log(target_sheet);
- var ws = wb.Sheets[target_sheet];
- console.log(ws);
- console.log(make_csv(ws));
- console.log(get_formulae(ws));
+var utils = {
+ make_csv: make_csv,
+ get_formulae: get_formulae
+};
+
+var readFile = function(f) { return parse_xlscfb(CFB.read(f, {type:'file'})); }
+if(typeof exports !== 'undefined') {
+ exports.readFile = readFile;
+ exports.utils = utils;
+ if(typeof module !== 'undefined' && require.main === module ) {
+ var wb = readFile(process.argv[2] || 'Book1.xls');
+ var target_sheet = process.argv[3] || '';
+ if(target_sheet === '') target_sheet = wb.Directory[0];
+ var ws = wb.Sheets[target_sheet];
+ console.log(target_sheet);
+ console.log(make_csv(ws));
+ //console.log(get_formulae(ws));
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.