Skip to content

Instantly share code, notes, and snippets.

@atljeremy
Created April 6, 2012 19:03
Show Gist options
  • Save atljeremy/2322098 to your computer and use it in GitHub Desktop.
Save atljeremy/2322098 to your computer and use it in GitHub Desktop.
Parse XLS Spreadsheet into Multi-Line Hash Using Ruby
# Required Gems
require "rubygems"
require "spreadsheet"
def getPixelTrackers
main=Hash.new
Spreadsheet.open('public/chart.xls') do |book|
book.worksheet('Sheet1').each do |row|
key = row[0].to_s.sub("\.0", "")
trackerHash = {
"impression" => row[2],
"click" => row[3],
"email" => row[4],
"phone" => row[5],
"coupon" => row[6]
}
referrerHash = {
row[1] => trackerHash
}
if main.has_key?(key)
main[key].merge!(referrerHash)
else
dmaHash = { key => referrerHash }
main = main.merge(dmaHash)
end
end
end
puts main
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment