Created
September 1, 2014 04:12
-
-
Save mani95lisa/15e4f9da586249202c35 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| XLSX = require('xlsx') | |
| sheet_from_array_of_arrays = (data, opts) -> | |
| ws = {} | |
| range = | |
| s: | |
| c: 10000000 | |
| r: 10000000 | |
| e: | |
| c: 0 | |
| r: 0 | |
| R = 0 | |
| while R isnt data.length | |
| C = 0 | |
| while C isnt data[R].length | |
| range.s.r = R if range.s.r > R | |
| range.s.c = C if range.s.c > C | |
| range.e.r = R if range.e.r < R | |
| range.e.c = C if range.e.c < C | |
| cell = v: data[R][C] | |
| cell.v = '' unless cell.v | |
| cell_ref = XLSX.utils.encode_cell( | |
| c: C | |
| r: R | |
| ) | |
| if typeof cell.v is "number" | |
| cell.t = "n" | |
| else if typeof cell.v is "boolean" | |
| cell.t = "b" | |
| else | |
| cell.t = "s" | |
| ws[cell_ref] = cell | |
| ++C | |
| ++R | |
| ws["!ref"] = XLSX.utils.encode_range(range) if range.s.c < 10000000 | |
| ws | |
| ws_name = "Data" | |
| module.exports.export = (data, filename)-> | |
| console.log(XLSX.version) | |
| wb = SheetNames:[],Sheets:{} | |
| console.log data.length | |
| ws = sheet_from_array_of_arrays(data) | |
| wb.SheetNames.push ws_name | |
| wb.Sheets[ws_name] = ws | |
| return XLSX.write wb, {type:'buffer'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment