cartodb-4.42/script/xls2csv.rb
2024-04-06 05:25:13 +00:00

24 lines
487 B
Ruby

require 'rubygems'
require 'roo'
if ARGV[0].nil?
puts "You should indicate a file to import"
return -1
else
unless File.file?(ARGV[0])
puts "File #{ARGV[0]} not found"
return -1
end
ext = File.extname(ARGV[0])
csv_name = File.basename(ARGV[0], ext)
s = case ext
when '.odt'
Openoffice.new(ARGV[0])
when '.xls'
Roo::Excel.new(ARGV[0])
when '.xlsx'
Roo::Excelx.new(ARGV[0])
end
s.to_csv("/tmp/#{csv_name}.csv")
puts "/tmp/#{csv_name}.csv"
end