Excel Export
nicolaslopezj:excel-export
Export data to excel in Meteor.
Excel.export(title, fields, data)
:
title
:String
. The name of the file.fields
:[field]
. Description of the fields to include in the file.data
:[Object]
. Array of data.
field
:
key
:String
. The path to the key, accept dot for nesting.title
:String
. The title of the column.type
:String
. Optional. The type of the data for the column, defaults tostring
. Allowed values:string
,date
,bool
andnumber
.width
:Number
. Optional. The width of the column. defaults to28.7109375
.transform
:Function
. Optional. A function that takes the value of the field as the first argument and the document as the second, must return the new value for the row.
Example:
1Router.route('/download-data', function() { 2 var data = Posts.find().fetch(); 3 var fields = [ 4 { 5 key: 'id', 6 title: 'URL', 7 transform: function(val, doc) { 8 return Router.url('posts.show', { _id: val }); 9 } 10 }, 11 { 12 key: 'message', 13 title: 'Message' 14 }, 15 { 16 key: 'viewsCount', 17 title: 'Views', 18 type: 'number' 19 } 20 ]; 21 22 var title = 'Posts'; 23 var file = Excel.export(title, fields, data); 24 var headers = { 25 'Content-type': 'application/vnd.openxmlformats', 26 'Content-Disposition': 'attachment; filename=' + title + '.xlsx' 27 }; 28 29 this.response.writeHead(200, headers); 30 this.response.end(file, 'binary'); 31}, { where: 'server' });