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

https://github.com/vamsipavanmahesh/example-excel-reader

gates
  • 4,465
  • 7
  • 32
  • 60

3 Answers3

1

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.

John Messenger
  • 351
  • 1
  • 8
1

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

Magda Sz.
  • 141
  • 1
  • 1
  • 6
0
worksheet.extract_data

give you entire sheet rows

worksheet.extract_data[0]

give you the first row

Yi Feng Xie
  • 4,378
  • 1
  • 26
  • 29