Skip to content

Instantly share code, notes, and snippets.

@ninjs
Created April 14, 2015 20:12
Show Gist options
  • Save ninjs/987aa54b870876b152e1 to your computer and use it in GitHub Desktop.
Save ninjs/987aa54b870876b152e1 to your computer and use it in GitHub Desktop.
def ub04
book = RubyXL::Parser.parse('ub04.xlsx')
newbook = RubyXL::Workbook.new
newsheet1 = newbook[0]
# THIS CODE IS FINE
print newsheet1[0][2]
sheet1 = book[0]
sheet1.each_with_index() { |row, index |
break if row[0].value == nil
next if index == 0
# Column 3
col_3 = row[104].value.to_s.split(/,/)[0]
# Column 4
col_4 = row[9].value.to_s.split(/, /)[1].capitalize + " " + row[9].value.to_s.split(/, /)[0].capitalize
# Column 6
col_6 = row[102].value.to_s
# Column 9
col_9 = row[6].value.to_s + '-' + row[7].value.to_s
# Column 10
col_10 = row[101].value.to_s
# Column 14
col_14 = "Sent on " + row[101].value.to_s
# Column 16
z = row[91].value.to_s.split(/,/)[0]
if z == 'H0010'
col_16 = 'DTX'
elsif z == 'H0018'
col_16 = 'RTC'
elsif z == 'H0017'
col_16 = 'RTC'
elsif z == 'S0201'
col_16 = 'PHP'
elsif z == 'H2036'
col_16 = 'PHP'
elsif z == 'H0035'
col_16 = 'PHP'
elsif z == 'H0015'
col_16 = 'IOP'
elsif z == 'S9480'
col_16 = 'IOP'
elsif z == '90853'
col_16 = 'GOP'
elsif z == '90837'
col_16 = 'GOP'
elsif z == '90834'
col_16 = 'GOP'
elsif z == '90832'
col_16 = 'GOP'
elsif z == 'G0431QW'
col_16 = 'POC'
elsif z == '80301'
col_16 = 'POC'
elsif z == '99205'
col_16 = 'MM'
elsif z == '99204'
col_16 = 'MM'
elsif z == '99245'
col_16 = 'MM'
elsif z == '99214'
col_16 = 'MM'
elsif z == '99213'
col_16 = 'MM'
elsif z == 'J2315'
col_16 = 'VIV'
elsif z == '96372'
col_16 = 'VIV'
else
col_16 = 'unknown code'
end
# Column 17
x = row[91].value.to_s.delete('"')
col_17 = x.split(/,/).count
# THIS CODE ERRORS OUT, undefined method '[]' for nil:NilClass (NoMethodError)
print newsheet1[0][2] + 'Hi'
}
newbook.write('output-ub04.xlsx')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment