Skip to content

Instantly share code, notes, and snippets.

@zhangxu
Last active February 23, 2016 22:28
Show Gist options
  • Save zhangxu/8bd714d754a62a9685af to your computer and use it in GitHub Desktop.
Save zhangxu/8bd714d754a62a9685af to your computer and use it in GitHub Desktop.
Read from Xls File
require 'roo'
path = '/workspace/data/import.xls'
file_type = `file -b --mime-type #{path}`.strip
xls =
case file_type
when 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/xml', 'application/vnd.ms-office'
Roo::Spreadsheet.open(path)
else
nil
end
xls.sheets.each { |sheet|
read_from_row = lambda { |row|
puts "sheet: #{sheet}"
puts row
}
xls.sheet(sheet).each_with_index { |row, idx|
if idx == 1
end
read_from_row.call(row)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment