Skip to content

mr5080att/xls_porter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

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.

About

Gem for exporting to xls and importing from xls to ActiveRecord

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages