Are you sure you want to write your own code for handling Excel binary format?
I suggest you try  'spreadsheet' gem.

require 'spreadsheet'
book = Spreadsheet::Workbook.new
sheet = book.create_worksheet
book.write 'test.xls'

-- 
cheers,
junegunn choi.