Created
December 2, 2013 19:46
-
-
Save mallorydxw/7756841 to your computer and use it in GitHub Desktop.
Apparently converting XLSX to CSV and keeping formulae intact is not something you can Google and find out how to do it? This is how you do it.
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 'rubygems' | |
require 'csv' | |
require 'roo' | |
excel = Roo::Excelx.new('filename.xlsx') | |
CSV do |csv| # (stdout) | |
excel.sheets.each do |s| | |
sheet = excel.sheet(s) | |
1.upto(excel.last_row) do |y| | |
row = [] | |
1.upto(excel.last_column) do |x| | |
if sheet.formula?(y, x) | |
row << '=' + sheet.formula(y, x) | |
else | |
row << sheet.cell(y, x) | |
end | |
end | |
csv << row | |
end | |
csv << ['----------'] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment