Created
July 2, 2012 12:35
-
-
Save amaunz/3033018 to your computer and use it in GitHub Desktop.
Convert XLS to CSV
This file contains hidden or 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
# Generate a csv from xls using ruby with a HERE document | |
# uses ruby's 'roo' gem | |
# Creates output for every sheet separately | |
# Usage: xls2csv </path/to/xlsfile.xls> | |
xls2csv () { | |
if [ ! -f $1 ]; then | |
echo "File '$1' not found." | |
exit 1 | |
fi | |
ruby <<EOF | |
require 'rubygems' | |
require 'roo' | |
file = "$1" | |
xls = Excel.new(file) | |
xls.sheets.each { |s| | |
xls.default_sheet = s | |
xls.to_csv("#{s}.csv") | |
} | |
puts file | |
EOF | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this code for converting excel to csv..but two questions i have