Question

Hi I am trying to compare a cell value in the spreadhseet with a string as given below.

workbook = Spreadsheet::ParseExcel.parse(name)

#Get the first worksheet
worksheet = workbook.worksheet(0)
puts worksheet.cell(4,0).to_s 
puts "SecurityKey".to_s
puts "SecurityKey".to_s.eql? worksheet.cell(4,0).to_s

I tried == , .eq? and all other possible string comparison techniques but it always results as false even when the two strings are the same. Can u help me out??

Thanks in advance

Was it helpful?

Solution

A cell object has numerous child objects and methods. The Value (read/write) method returns a Cell's value as it is stored internally. A cell's Text (read-only) method returns the value as it is currently displayed. For example, if cell has the value "1234.56789" formatted as Currency, the Value and Text methods return different values

http://rubyonwindows.blogspot.com/2007/04/automating-excel-with-ruby-rows-columns.html

Try using value or text

worksheet.Cells(4, 0).Value == "SecurityKey"
worksheet.Cells(4, 0).Text == "SecurityKey"

Edit

Avoid using parseexcel. Try something like

require 'spreadsheet'

Spreadsheet.client_encoding = 'UTF-8'
workbook = Spreadsheet.open '/path/to/file.xls'
first_sheet = workbook.worksheet 0 # or name
cell = first_sheet.row(1).at(4)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top