Last active
December 16, 2015 12:09
-
-
Save ysinc88/6f87944354e16e54d3cd to your computer and use it in GitHub Desktop.
Loading xls with roo
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
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