Last active
August 29, 2015 13:56
-
-
Save bluetwin/8911678 to your computer and use it in GitHub Desktop.
Trivial example of writing to a spreadsheet using a buffer
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
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