workbook = RubyXL::Parser.parse(params[:file].path)
worksheet = workbook[0]
puts worksheet.sheet_data[0][0]But I am getting this as output
<RubyXL::Cell(0,0): "0", datatype="s", style_index=1>My excel sheet is of this form
name coupon gates gates1234 jobs jobs1234I want to access rows one by one .. any help will be appreciated.
I also made a sample app for this post, if you want to run it ..
3 Answers
worksheet.sheet_data[0]gives you a Ruby object representing the first row.
worksheet.sheet_data[0][0]gives you a Ruby object representing the first cell on the first row. But to get the actual contents of that cell, you need
worksheet.sheet_data[0][0].value
The worksheet is organised as an array of cells. You have to deal with the cells one by one in each row, if you are processing the rows sequentially.
2worksheet[0].cells.map(&:value) work for me
I was trying worksheet.extract_data[0] but extract_data is no longer available in RubyXL (I use v.3.3.3)!
worksheet.extract_datagive you entire sheet rows
worksheet.extract_data[0]give you the first row