Skip to content

Instantly share code, notes, and snippets.

@ysinc88
Last active December 16, 2015 12:09
Show Gist options
  • Save ysinc88/6f87944354e16e54d3cd to your computer and use it in GitHub Desktop.
Save ysinc88/6f87944354e16e54d3cd to your computer and use it in GitHub Desktop.
Loading xls with roo
class CatalogTemplatesController < ApplicationController
.
.
.
def parse
require 'roo'
require 'roo-xls'
workbook = Roo::Excel.new("/home/123.xls")
workbook.sheets.each do |s|
#puts workbook
workbook.default_sheet = s
line=30
((workbook.first_row + line)..workbook.last_row).each do |row|
label = workbook.sheet(s).cell(5,3)
title = workbook.sheet(s).cell(7,3)
releaseDate = workbook.sheet(s).cell(4,2)
artist = workbook.sheet(s).cell(6,3)
releaseType = workbook.sheet(s).cell(8,3)
genre = workbook.sheet(s).cell(12,3)
subGenre = workbook.sheet(s).cell(13,3)
upc = workbook.sheet(s).cell(14,3)
trackArtist = workbook.row(row)[2]
trackTitle = workbook.row(row)[3]
trackVersion = workbook.row(row)[4]
trackIsrc = workbook.row(row)[6]
@create = CatalogTemplate.create(
:label => label,
:releaseTitle => title,
:releaseVersion => releaseType,
:artist => artist,
:artistRole => "Primary",
:releaseType => "Album",
:upc => upc,
:catalogId => "",
:releaseDate => releaseDate,
:genre => genre,
:genre2 => subGenre,
:trackTitle => trackTitle,
:trackVersion => trackVersion,
:trackArtist => trackArtist,
:trackArtistRole => "",
:isrc => trackIsrc,
:sourceIsrc => "")
end # end tracklist which start at line 33
#print "#{label},#{artist},#{title},#{releaseType},#{genre},#{subGenre},#{upc},#{@trackArtist},#{@trackTitle},#{@trackVersion},#{@trackIsrc}\n"
end # end each sheet
if @create
redirect_to root_path
else
p "Woops"
end
end
.
.
.
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment