To create multiple sheets in a single excel sheet , its good to use spreadsheet gem. In your controller (suppose card is your controller) add the following:
def export
book = Spreadsheet::Workbook.new
sheet1 = book.create_worksheet :name => 'Sheet1'
sheet2 = book.create_worksheet :name => 'Sheet2'
sheet1.row(0).push "some content in Column1" //to push content in 1st row 1st column of 1st spreadsheet
//keep pushing on row(0) if you want to push contents other columns of 1st row
spreadsheet = StringIO.new
book.write spreadsheet
file = "Excelsheet"
send_data spreadsheet.string, :filename => "#{file}", :type => "application/vnd.ms-excel"
end
In you view
<%=link_to("Export Database to Excel", cards_url + "/export") %>
No comments:
Post a Comment