Skip to content

Instantly share code, notes, and snippets.

@morganchristiansson
Created January 30, 2014 12:26
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 morganchristiansson/8707434 to your computer and use it in GitHub Desktop.
Save morganchristiansson/8707434 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'spreadsheet'
input_path = ARGV[0] or abort('Expecting .xls file as argument')
output_path = input_path.sub(/\.xls$/, '-out.xls')
book = Spreadsheet.open(input_path)
# This is a fix/workaround - modifying each sheet in the workbook.
# Without it, the output file doesn't open at all
#
# After resaving the file in Excel for Mac 2011 the output file
# generates warning on open and is sometimes missing data
#
book.worksheets.each do |sheet|
sheet.each(0) { |row| row.replace row }
end
# Without the code above this line breaks the output file completley
book.worksheet(0).row(0)[0] = ''
book.write(output_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment