Skip to content

Instantly share code, notes, and snippets.

@mrrooijen
Created May 14, 2010 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrrooijen/401092 to your computer and use it in GitHub Desktop.
Save mrrooijen/401092 to your computer and use it in GitHub Desktop.
Simple Excel Parse script.
# Load in required libraries
require 'rubygems'
require 'parseexcel'
# Load workbook into memory
workbook = Spreadsheet::ParseExcel.parse("file.xls")
# Open first worksheet
worksheet = workbook.worksheet(0)
# Creates array to hold a Hash of parsed participants
records = Array.new
# Runs through each row of the first worksheet
worksheet.each do |entry|
unless entry.nil?
records << {
:row1 => entry[0],
:row2 => entry[1],
:row3 => entry[2]
}
end
end
# Encodes all data from crypted .xls format to latin1
records.each do |record|
record.each do |key, value|
record[key] = record[key].to_s('latin1') unless record[key].nil?
end
end
# "records" contains all the data from the XLS file
puts records.first[:row1] # => etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment