how to use rubyxl to access the first row

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 jobs1234

I 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.

2

worksheet[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)!

1
worksheet.extract_data

give you entire sheet rows

worksheet.extract_data[0]

give you the first row

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like