Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
dominictarr committed May 15, 2014
0 parents commit 486d73d
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 0 deletions.
22 changes: 22 additions & 0 deletions LICENSE
@@ -0,0 +1,22 @@
Copyright (c) 2014 Dominic Tarr

Permission is hereby granted, free of charge,
to any person obtaining a copy of this software and
associated documentation files (the "Software"), to
deal in the Software without restriction, including
without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom
the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
59 changes: 59 additions & 0 deletions README.md
@@ -0,0 +1,59 @@
# excel-stream

A stream that converts excel spreadsheets into JSON object arrays.

# Example

``` js
var excel = require('excel-stream')
var fs = require('fs')

fs.createReadStream('accounts.xlsx')
.pipe(excel())
.on('data', console.log)

```

# Usage

``` js
npm install -g excel-stream
excel-stream < accounts.xlsx > account.json
```

# formats

each row becomes a javascript object, so input like

``` csv
foo, bar, baz
1, 2, 3
4, 5, 6
```

will become

``` js
[{
foo: 1,
bar: 2,
baz: 3
}, {
foo: 4,
bar: 5,
baz: 6
}]

```

# Don't Look Now

So, excel isn't really a streamable format.
But it's easy to work with streams because everything is a stream.
This writes to a tmp file, then pipes it through the unfortunately named [j](https://npm.im/j)
then into [csv-stream](https://npm.im/csv-stream)


## License

MIT
41 changes: 41 additions & 0 deletions index.js
@@ -0,0 +1,41 @@
#! /usr/bin/env node

var fs = require('fs')
var path = require('path')
var spawn = require('child_process').spawn

var through = require('through')
var csv = require('csv-stream')
var osenv = require('osenv')
var duplexer = require('duplexer')

module.exports = function () {

var read = through()

var filename = path.join(osenv.tmpdir(), '_'+Date.now())
var write = fs.createWriteStream(filename)
.on('close', function () {
var child = spawn(require.resolve('j/bin/j.njs'), [filename])
child.stdout.pipe(csv.createStream())
.pipe(through(function (data) {
for(var k in data)
if(!k) delete data[k]
this.queue(data)
}))
.pipe(read)
})

return duplexer(write, read)

}


if(!module.parent) {
var JSONStream = require('JSONStream')

process.stdin
.pipe(module.exports())
.pipe(JSONStream.stringify())
.pipe(process.stdout)
}
24 changes: 24 additions & 0 deletions package.json
@@ -0,0 +1,24 @@
{
"name": "excel-stream",
"description": "",
"version": "0.0.0",
"homepage": "https://github.com/dominictarr/excel-stream",
"repository": {
"type": "git",
"url": "git://github.com/dominictarr/excel-stream.git"
},
"dependencies": {
"through": "~2.3.4",
"duplexer": "~0.1.1",
"JSONStream": "~0.8.2",
"csv-stream": "~0.1.3",
"osenv": "~0.0.3",
"j": "~0.2.20"
},
"devDependencies": {},
"scripts": {
"test": "set -e; for t in test/*.js; do node $t; done"
},
"author": "Dominic Tarr <dominic.tarr@gmail.com> (http://dominictarr.com)",
"license": "MIT"
}

0 comments on commit 486d73d

Please sign in to comment.