Home

Awesome

Excel Export

nicolaslopezj:excel-export

Export data to excel in Meteor.

Excel.export(title, fields, data):

field:

Example:

Router.route('/download-data', function() {
  var data = Posts.find().fetch();
  var fields = [
    {
      key: 'id',
      title: 'URL',
      transform: function(val, doc) {
        return Router.url('posts.show', { _id: val });
      } 
    },
    {
      key: 'message',
      title: 'Message'
    },
    {
      key: 'viewsCount',
      title: 'Views',
      type: 'number'
    }
  ];

  var title = 'Posts';
  var file = Excel.export(title, fields, data);
  var headers = {
    'Content-type': 'application/vnd.openxmlformats',
    'Content-Disposition': 'attachment; filename=' + title + '.xlsx'
  };

  this.response.writeHead(200, headers);
  this.response.end(file, 'binary');
}, { where: 'server' });