can read the spreadsheet each row.(need to think of a method to parse each row to figure)
This commit is contained in:
1 parent
01ce52060b
commit
ea3edbf7ac
2 files changed
+21
No files matched your search
+18
@@ -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
|
||||
|
||||
Reference in new issue
Block a user