Open kirykr opened 8 years ago
Hi @kirykr, Can you attach an example from your xlsx ?.
Ok here I found the solution. after leaving this quite awhile, i came back and found out that if the sheet.row(1)
contains:
[2] pry(main)> attributes
=> {"No"=>"No",
"Name"=>"Name",
"Mobile"=>"Mobile",
"Email (Personal)"=>"Email (Personal)",
"Email (Rotati)"=>"Email (Rotati)",
"Date of Birth"=>"Date of Birth",
nil=>nil}
nil=>nil
it will be raised the Roo::HeaderRowNotFoundError (Roo::HeaderRowNotFoundError)
so what I just did is to attributes.compact
compact the array to flash out the nil
sheet.each(attributes.compact) do |hash|
if(!first_row)
(final_json[sheet_name] ||= []) << hash
end
first_row = false
end
``
ruby excel_to_json.rb excel_file.xlsx /home/kr/.rvm/gems/ruby-2.3.1@ruby231rail5001/gems/roo-2.5.1/lib/roo/base.rb:400:in'
row_with': Roo::HeaderRowNotFoundError (Roo::HeaderRowNotFoundError) from /home/kr/.rvm/gems/ruby-2.3.1@ruby231rail5001/gems/roo-2.5.1/lib/roo/base.rb:574:in
set_headers' from /home/kr/.rvm/gems/ruby-2.3.1@ruby231rail5001/gems/roo-2.5.1/lib/roo/base.rb:469:insearch_or_set_header' from /home/kr/.rvm/gems/ruby-2.3.1@ruby231rail5001/gems/roo-2.5.1/lib/roo/base.rb:366:in
each' from excel_to_json.rb:30:inblock (2 levels) in <main>' from excel_to_json.rb:23:in
each' from excel_to_json.rb:23:inblock in <main>' from excel_to_json.rb:9:in
each' from excel_to_json.rb:9:in `