how can i create a excel file, supported by all excel versions, and send it
to the browser (like i did with fpdf for pdf)
does anybody has some sample code
this is what i have in controller
require "spreadsheet/excel"
include Spreadsheet
def export_excel
if @request.env[''HTTP_USER_AGENT''] =~ /msie/i
@headers[''Pragma''] = ''''
@headers[''Cache-Control''] = ''''
else
@headers[''Pragma''] = ''no-cache''
@headers[''Cache-Control''] = ''no-cache,
must-revalidate''
end
send_data gen_excel, :filename => "timesheets.xls", :type =>
"application/vnd.ms-excel"
end
def gen_excel
@employee_id = @params["employee_id"]
@geotag_id = @params["geotag_id"]
firm_id = @session[:user].id
corrected_server_date = (Time.now).strftime(''%Y-%m-%d
00:00:00'')
@time_entries = TimeEntry.find(:all, :conditions
=>["time_entries.firm_id =
? AND employee_id like ? and geotag_id like ?", firm_id,
"%#{@employee_id}%", "%#{@geotag_id}%"], :order =>
"time_entries.start_time
DESC", :include=>[:employee,:geotag])
wb = Excel.new("test.xls")
version = Excel::VERSION
# Preferred way to add a format
#f1 = wb.add_format(:color=>"blue",:bold=>1,:italic=>true)
ws = wb.add_worksheet("timesheets")
ws.write(5,0,"This should be blue")
wb.close
end
i used spreadsheet from http://rubyspreadsheet.sourceforge.net/
or anyone got any betters
ERROR:
WARNING: You have a nil object when you probably didn''t expect it!
Odds
are you
want an instance of Array instead.
Look in the callstack to see where you''re working with an object that
could
be nil.
Investigate your methods and make sure the object is what you expect!