Skip to content

Instantly share code, notes, and snippets.

@masukomi
Created April 25, 2013 15:00
Show Gist options
  • Save masukomi/5460367 to your computer and use it in GitHub Desktop.
Save masukomi/5460367 to your computer and use it in GitHub Desktop.
a simple shell script to expose a bug in the spreadsheet gem
#!/usr/bin/env ruby
# it expects you're going to pass it the spreadsheet found here
# http://masukomi.org/misc/spreadsheet_float_test.xls
raise "Needs a path argument" unless ARGV[0]
require 'spreadsheet'
file_path = ARGV[0]
Spreadsheet.client_encoding = 'UTF-8'
book = Spreadsheet.open(StringIO.new(File.read(file_path)))
sheet = book.worksheets.first
row_num = 1
sheet.each 1 do |row|
puts "row #{row_num} column 0: #{row[0]} & is_a #{row[0].class.name}"
row_num += 1
end
@zdavatz
Copy link

zdavatz commented Apr 26, 2013

How about:

{row[0].to_s.class.name}

@Marinofull
Copy link

@zdavatz & is_a #{row[0].class.name}" this part of code is just an example to show as it is coming as Float instead String.
He wants to get the value from row[0] as it was in the source spreadsheet, a string, and not write the last part of the message to String.

@Victorcorcos
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment