My HTML code, here am passing xslx file for parsing,
<form method="post" action="/home/parse_xlsx" enctype="multipart/form-data">
Upload XSLX File <input type="file" name="xlsx_file" id="xlsx_file" />
<input type="submit" value="Post"/>
</form>
My Controller code,
def parse_xlsx
xlsxFile = params[:xlsx_file]
prefix_tmp_path = xlsxFile.path
filename = xlsxFile.original_filename
fullname = File.join(prefix_tmp_path,filename)
require 'roo'
s = Roo::Excelx.new(fullname)
for i in 1..14
puts s.cell(i,3)
end
end
Giving me error ,
file /tmp/RackMultipart20130910-10043-u4nqsc/CMS.xlsx does not exist
When I run the following code on console am keeping my 'CMS.xlsx' file in rails root folder & it is running without any errors.
require 'roo'
s = Roo::Excelx.new("CMS.xlsx")
for i in 1..14
puts s.cell(i,3)
end
Please explain where I am going wrong.
xlsxFile.path is the file's location, you shouldn't have to join in the filename. If you need to save the file, you can rename it the original filename when you move it to it's file location
try
s = Roo::Excelx.new(xlsxFile.path)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.