XlsxtreamRails

Xlsx stream download for rails.

Installation

Add this line to your application's Gemfile:

gem "xlsxtream_rails"

And then execute:

$ bundle

Or install it yourself as:

$ gem install xlsxtream_rails

Controller

Set your instance variables in your controller and configure the response if needed:

class PostsController < ApplicationController
  def index
    @posts = Post.all
    respond_to do |format|
      format.xlsx { render xlsx: @posts }
    end
  end
end

Model

Add xlsx_columns method for model:

class Post < ApplicationRecord
   def xlsx_columns
     [:id, :title, :body]
   end
end

or

class Post < ApplicationRecord
   belongs_to :category

   def xlsx_columns
     [
       [:category, category.name],
       :title,
       :body
    ]
   end
end

This gem is inspired by the following

spreadsheet_architect

caxlsx_rails

License

The gem is available as open source under the terms of the MIT License.