Last active
November 27, 2018 10:25
-
-
Save xiejiangzhi/5464fa803e4260bde54b919c7e9219a3 to your computer and use it in GitHub Desktop.
Convert excel(xls, xlsx, etc) to csv
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
#! /usr/bin/env ruby | |
# Support formats | |
# xlsx: Excel 2007 - 2013 | |
# xlsm: Excel 2007 - 2013 | |
# xls: Excel 97, | |
# ods: LibreOffice / OpenOffice.org | |
# xml: Excel 2002 2003 XML | |
# | |
# More see roo-rb/roo | |
require 'csv' | |
require 'roo' | |
require 'roo-xls' | |
path, sheet = ARGV.first.split(':') | |
puts "not found file" unless File.exists?(path) | |
xlsx = Roo::Spreadsheet.open(path) | |
str = CSV.generate do |csv| | |
xlsx.sheet(sheet.to_i).to_a.each { |row| csv << row } | |
end | |
puts str |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment