Project

xls_porter

0.0
No commit activity in last 3 years
No release in over 3 years
Export to and Import from XLS for Ruby and Rails apps
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 0.6.2
 Project Readme

Welcome to xls_porter¶ ↑

Simple data export to XLS and import from XLS to ActiveRecord model. The source is available at github.com/mr5080att/xls_porter.git.

Dependencies¶ ↑

  1. CarrierWave for file uploading.

  2. Ruby Spreadsheet.

Mixins: Extending a class.¶ ↑

class MyXlsPorter
  extend XlsPorter
end

MyXlsPorter.to_xls(User.all, %w(id name first_name last_name), "Users")

Mixins: Including in a class.¶ ↑

file: app/controllers/application_controller.rb

class ApplicationController < ActionController::Base
  include XlsPorter
end

Instances of the classes that inherits from ApplicationController will have access to xls_porter methods.

file: app/controllers/networks_controller.rb

class NetworkController < ApplicationController

  # /networks/xls_download
  def xls_download
    model_to_xls(Network).write(stream = StringIO.new)
    send_data(stream.string, :filename => "#{Network.name.pluralize}.xls", :type => "Application/Excel")
  end

  # /networks/xls_upload
  def xls_upload
    @model_updates = xls_upload_and_update_model(params[:data_file], Network)
    render "uploaded/uploaded_updates"
  end

end

The uploaded data file is stored in “tmp/upload” temporarily and deleted after the method xls_upload_and_update_model completes successfully.