Skip to content

GUI/fast_excel_rails

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastExcelRails

A Rails template handler for the fast_excel gem.

Installation

Add this line to your application's Gemfile:

gem "fast_excel_rails"

And then execute:

$ bundle install

Usage

Controllers

The default template file for your controller action can be rendered using format.xlsx:

class ThingsController < ApplicationController
  def index
    @things = (1..1000).to_a
    respond_to do |format|
      format.xlsx
    end
  end
end

Other options, like filenames or custom template paths, can be set using an explicit render call:

class ThingsController < ApplicationController
  def index
    respond_to do |format|
      format.xlsx { render :xlsx => "my filname.xlsx", :template => "custom_template"
    end
  end
end

Templates

Templates use the .xlsx.fast_excel extension and are normal Ruby files that have access to a workbook variable that is a FastExcel::Workbook instance.

For example, app/views/things/index.xlsx.fast_excel:

worksheet = workbook.add_worksheet

worksheet.append_row(["Message", "Price", "Date"], workbook.bold_format)

@things.each do |i|
  worksheet << ["Hello", (rand * i).round(2), Time.now])
end

See fast_excel for further information on usage syntax.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fast_excel_rails.

License

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

About

A Rails template handler for the fast_excel gem.

Resources

License

Stars

Watchers

Forks

Packages

No packages published