diff --git a/Gemfile b/Gemfile index 16c820c9a..3cfa8c2d0 100644 --- a/Gemfile +++ b/Gemfile @@ -29,6 +29,9 @@ gem 'mongoid-tree', :require => 'mongoid/tree' gem "mongo_session_store-rails3", '3.0.6' gem 'nokogiri' +# export csv +gem 'roo' + gem 'fb_graph' gem 'rack-gridfs' gem 'radius' diff --git a/vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb b/vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb index 621efcb39..28feddc20 100644 --- a/vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb +++ b/vendor/built_in_modules/survey/app/controllers/panel/survey/back_end/surveys_controller.rb @@ -1,4 +1,6 @@ require 'csv' +require 'iconv' +require 'roo' class Panel::Survey::BackEnd::SurveysController < OrbitBackendController @@ -90,6 +92,22 @@ class Panel::Survey::BackEnd::SurveysController < OrbitBackendController end 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 def export