Reputation: 3247
I receive the following error while using Ruby 2.0 with the Spreadsheet Gem:
%': can't convert Spreadsheet::Column into Integer (TypeError)
I am using the spreadsheet guide for the spreadsheet gem.
require 'spreadsheet'
importing = Spreadsheet.open 'file.xls'
book = importing.worksheet 'Sheet1'
book.each do |x, y|
x = book.column(1)
y = book.column(2)
puts x
puts y
end
I am expecting an output like this since that is what I have in the spreadsheet:
x y
32 4
402 6
733 4
1 30
2 3128
2 4
1 1
6 2
10 63
90 333
Upvotes: 0
Views: 72
Reputation: 18351
The each
method iterates over each row in the spreadsheet. You can then access each value in the row using []
s. This part of the guide is relevant.
Try something like this for your use case:
require 'spreadsheet'
importing = Spreadsheet.open 'file.xls'
book = importing.worksheet 'Sheet1'
book.each do |row|
puts "%-4s%-4s" % row
end
%-4s
means insert a left-justified String with a min-width of 4 spaces. The first two elements in row
will be substituted in because we have two %
arguments in the string.
Upvotes: 1