Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import mpr
class Plan < ActiveRecord::Base
include Roo
def self.import
s = Excelx.new("#{Rails.root}/db/data/simple_media_plan.xlsx")
table_start_row_no = s.first_row
table_end_row_no = s.last_row
# Find the start and end row of the table
s.first_row.upto(s.last_row) do |line|
if s.cell(line, 2) == "Placement Description"
table_start_row_no = line + 1
elsif s.cell(line, 2) == "Total Cost:"
table_end_row_no = line -1
end
end
table_start_row_no.upto(table_end_row_no) do |line|
row_hash = {
:placement_description => s.cell(line, 2),
:geo_targets => s.cell(line, 3),
:ad_units => s.cell(line, 4),
:cpm => s.cell(line, 5),
:impressions => s.cell(line, 6),
:net_cost => s.cell(line, 7),
:start_date => s.cell(line, 8),
:end_date => s.cell(line, 9),
:looping_animation => s.cell(line, 10),
:creative_lead_time => s.cell(line, 11),
:rich_media => s.cell(line, 12)
}
Plan.create!(row_hash)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.