Last active
February 23, 2016 22:28
-
-
Save zhangxu/8bd714d754a62a9685af to your computer and use it in GitHub Desktop.
Read from Xls File
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
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