Skip to content

Instantly share code, notes, and snippets.

@bluetwin
Last active August 29, 2015 13:56
Show Gist options
  • Save bluetwin/8911678 to your computer and use it in GitHub Desktop.
Save bluetwin/8911678 to your computer and use it in GitHub Desktop.
Trivial example of writing to a spreadsheet using a buffer
require 'spreadsheet'
def speadsheet_with_buffer
buf = StringIO.new
book = Spreadsheet::Workbook.new
sheet = book.create_worksheet :name => "New Worksheet"
sheet.row(0).concat %w{col_1, col_2, col_3}
sheet[1,0] = "next row, first column"
book.write buf
# using rails 'send_data', send the file in the buffer as the response
send_data buf.string, type: "application/ms-excel", disposition: "attachment", :filename => "my_new_xls_file.xls"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment