Created
May 14, 2010 12:28
-
-
Save mrrooijen/401092 to your computer and use it in GitHub Desktop.
Simple Excel Parse script.
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
# 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