Skip to content

Instantly share code, notes, and snippets.

@tune
Created December 4, 2012 02:13
Show Gist options
  • Save tune/4199911 to your computer and use it in GitHub Desktop.
Save tune/4199911 to your computer and use it in GitHub Desktop.
Parse Excel file using spreadsheet gem
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# Display all cell value except 1st sheet and 1st row
#
# Note: This script requires spreadsheet gem
# $ gem install spreadsheet
require 'rubygems'
require 'spreadsheet'
if ARGV.size < 1 then
puts 'Usage:\n $ ruby parse_xls.rb FILENAME'
exit(1)
end
book = Spreadsheet.open(ARGV[0])
# ignore 1st sheet since used for summary
book.worksheets[1..-1].each do |ws| # worksheet
puts ws.name
# ignore 1st row since used for title
ws.column(2).to_a[1..-1].each do |cv| # cell value
puts "\t#{cv}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment