can read the spreadsheet each row.(need to think of a method to parse each row to figure)
This commit is contained in:
parent
01ce52060b
commit
ea3edbf7ac
3
Gemfile
3
Gemfile
|
@ -29,6 +29,9 @@ gem 'mongoid-tree', :require => 'mongoid/tree'
|
||||||
gem "mongo_session_store-rails3", '3.0.6'
|
gem "mongo_session_store-rails3", '3.0.6'
|
||||||
gem 'nokogiri'
|
gem 'nokogiri'
|
||||||
|
|
||||||
|
# export csv
|
||||||
|
gem 'roo'
|
||||||
|
|
||||||
gem 'fb_graph'
|
gem 'fb_graph'
|
||||||
gem 'rack-gridfs'
|
gem 'rack-gridfs'
|
||||||
gem 'radius'
|
gem 'radius'
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
require 'csv'
|
require 'csv'
|
||||||
|
require 'iconv'
|
||||||
|
require 'roo'
|
||||||
|
|
||||||
class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
|
class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
|
||||||
|
|
||||||
|
@ -90,6 +92,22 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController
|
||||||
end
|
end
|
||||||
|
|
||||||
def import
|
def import
|
||||||
|
@survey = ::Survey.find(params[:id])
|
||||||
|
@file = params[:file]
|
||||||
|
|
||||||
|
case File.extname(@file.original_filename)
|
||||||
|
when ".csv" then @spreadsheet = Roo::CSV.new(@file.path)
|
||||||
|
# when ".xls" then Excel.new(file.path, nil, :ignore)
|
||||||
|
# when ".xlsx" then Excelx.new(file.path, nil, :ignore)
|
||||||
|
else raise "Unknown file type: #{file.original_filename}"
|
||||||
|
end
|
||||||
|
|
||||||
|
@header = @spreadsheet.row(1)
|
||||||
|
(2..@spreadsheet.last_row).each do |i|
|
||||||
|
##parse each row here
|
||||||
|
end
|
||||||
|
|
||||||
|
redirect_to panel_survey_back_end_surveys_url, :notice => :success
|
||||||
end
|
end
|
||||||
|
|
||||||
def export
|
def export
|
||||||
|
|
Loading…
Reference in New Issue