Skip to content

Instantly share code, notes, and snippets.

@mono0x
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mono0x/5a359cbec4c7cefb3b50 to your computer and use it in GitHub Desktop.
Save mono0x/5a359cbec4c7cefb3b50 to your computer and use it in GitHub Desktop.
Convert from xls/xlsx to TSV
#!/usr/bin/env ruby
require 'tmpdir'
SOFFICE = '~/Applications/LibreOffice.app/Contents/MacOS/soffice'.freeze
if ARGV.size != 1
STDERR.puts 'usage: xls2tsv filename'
exit 1
end
Dir.mktmpdir do |dir|
output = `#{SOFFICE} --headless --convert-to csv --infilter=CSV:9,34,UTF8 "#{ARGV[0]}" --outdir "#{dir}"`
path = output.match(/-> (.+?) using filter :/).to_a[1]
open(path) do |f|
print f.read
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment