1

Im trying to generate a *.xls(spreadsheet file) und and make in downloadable for a mobile device.

Well this works great for desktop browsers and the iphone, but the android will tell that the file couldnt be downloaded.

controller.rb

def index
   #find the Object
   respond_to do |format|
      ...         
      format.xls { send_data as_xls, content_type: 'application/vnd.ms-excel', filename: 'data.xls' }
   end
end

def as_xls(options = {})
   require 'spreadsheet'
   Spreadsheet.client_encoding = 'UTF-8'

   book = Spreadsheet::Workbook.new
   #only some work to create the sheet  
   ...
   require 'stringio'
   data = StringIO.new
   book.write data
   data.rewind
   #data.read
   data.string.bytes.to_a.pack("C*")
end

view.html.erb

model_name_path(@model, format: "xls")

Versions

Ruby 1.9.3

Rails 3.2.13

Alex
  • 327
  • 5
  • 8

0 Answers0