-
-
Save aya-soft/5099720 to your computer and use it in GitHub Desktop.
#encoding: utf-8 | |
require 'spreadsheet' | |
xls_file_name = "/tmp/status_data.xls" | |
xls_book = Spreadsheet.open(xls_file_name, "rb") | |
xls_book.worksheet(0).each do |row| | |
puts row[6].value if row[6] and row[6].is_a?(Spreadsheet::Formula) | |
end |
I am now trying this:
#encoding: utf-8
require 'spreadsheet'
xls_file_name = "/tmp/status_data.xls"
xls_book = Spreadsheet.open(xls_file_name, "rb")
xls_book.worksheet(0).each do |row|
puts row[6].try(:value) if row[6] and row[6].is_a?(Spreadsheet::Formula)
end
but I get this error:
aya.rb:10:in block in <main>': undefined method
try' for #Spreadsheet::Formula:0x000000022a5f38 (NoMethodError)
from /usr/local/lib64/ruby/gems/1.9.1/gems/spreadsheet-0.8.1/lib/spreadsheet/worksheet.rb:133:in block in each' from /usr/local/lib64/ruby/gems/1.9.1/gems/spreadsheet-0.8.1/lib/spreadsheet/worksheet.rb:132:in
upto'
from /usr/local/lib64/ruby/gems/1.9.1/gems/spreadsheet-0.8.1/lib/spreadsheet/worksheet.rb:132:in each' from /usr/local/lib64/ruby/gems/1.9.1/gems/spreadsheet-0.8.1/lib/spreadsheet/excel/worksheet.rb:35:in
each'
from aya.rb:9:in `
So I really need a clean script from you!
Best
Zeno
With above script I get
/tmp> ruby aya.rb
7.5
5.37
7.52
9.78
with your sample XLS (not modified by me) on my Gentoo Linux.
Best
Zeno
rspec output:
4.88
3.86
34.9
34.49
41.22
39.09
7.5
5.37
7.52
9.774999999999999
should get right price value
Finished in 0.10021 seconds
1 example, 0 failures