Last active
August 29, 2015 14:24
-
-
Save mono0x/5a359cbec4c7cefb3b50 to your computer and use it in GitHub Desktop.
Convert from xls/xlsx to TSV
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 | |
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