Created
December 4, 2012 02:13
-
-
Save tune/4199911 to your computer and use it in GitHub Desktop.
Parse Excel file using spreadsheet gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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