Downloading an excel file using Spreadsheet gem in rails app -
i using spreadsheet gem in rails app , want able download excel file generated spreadsheet. have following action in controller:
def download_xls send_data spreadsheet_report("test", prospects::inquiry_column_order), :filename => "test.xls", :type => "application/vnd.ms-excel" end
the spreadsheet_report
method defined in same controller:
def spreadsheet_report(excel_filename, inquiry_column_order) book = spreadsheet::workbook.new sheet1 = book.create_worksheet :name => array1[0] sheet2 = book.create_worksheet :name => array2[1] rownum = 0 column in inquiry_column_order sheet1.row(rownum).push column end book.write "#{excel_filename}.xls" end
the "test.xls" file downloads fine, seems losing necessary formatting, 1 worksheet being created , having values on first row stretch on , on, such "@biff_version=1536". opening libreoffice calc don't know if causes issues able generate file fine , open libreoffice calc outside of send_data context. missing?
sheet 2 being created not shown because there isn't in it.
just throw in -
sheet2.row(0).push 'test row'
to see if gets put second sheet.
for rows, looking @ code not incrementing rownum everytime loop through each column in inquiry_column_order.
just add
rownum += 1
in loop after push data onto sheet. hope works, started using spreadsheet today aswell :)
Comments
Post a Comment