diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/index.html b/index.html new file mode 100644 index 0000000..808222f --- /dev/null +++ b/index.html @@ -0,0 +1,68 @@ + +
++SheetJS Spreadsheet Conversion Service + +send a request to /data?url=<url>&N=<idx> to convert the spreadsheet at `url` to a simpler format + +parameters: +- url=<url> the url to request +- N=<idx> the sheet index to use (-1 returns a list of sheet names in the workbook) +- t=<type> export type: "json" for json, "html" for html, default is CSV + +examples: ++ + +
+This service is powered by SheetJS + +Source Code: + +- Source code for this service + +- Source code for the js-xlsx spreadsheet library ++ + + diff --git a/index.js b/index.js index b5794e8..a2488fb 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ var XLSX = require('xlsx'); var URL = require('url'); var request = require('request'); +var send = require('send'); var micro = require('micro'); function do_url(req, url, res) { @@ -23,28 +24,19 @@ function do_url(req, url, res) { var ws = wb.Sheets[wb.SheetNames[N]]; switch(url.query.t) { case "json": return micro.send(res, 200, JSON.stringify(XLSX.utils.sheet_to_json(ws, {header:1, raw:true}))); + case "html": return XLSX.stream.to_html(ws).pipe(res); default: XLSX.stream.to_csv(ws).pipe(res); } }); } - -var msg = [ - 'request /data?url=