-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleXLS.js
More file actions
32 lines (29 loc) · 854 Bytes
/
SimpleXLS.js
File metadata and controls
32 lines (29 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var exports = module.exports = {};
var streams = require('memory-streams');
var fs = require('fs');
/**
*
* Give me some columns and some datas to noms.
*
* Columns have the structure {'label': 'my infinitely expressive column name', 'name':'my_boring_database_semantic_name'}
* Rows (datas) have the structure {'my_boring_database_semantic_name': 'foo', 'my_other_semantic_name': 'bar'}
*
*/
exports.write_to_xls = function(columns, datas){
var write = new streams.WritableStream();
var header = "";
columns.forEach(function(column){
header += column.label + "\t";
});
header += "\n";
write.write(header);
datas.forEach(function(model){
var row = "";
columns.forEach(function(key){
row += model[key.name] + "\t";
});
row += "\n";
write.write(row);
});
return write;
};