From owner-cvs-all@FreeBSD.ORG Sat Oct 8 11:16:50 2005 Return-Path: X-Original-To: cvs-all@freebsd.org Delivered-To: cvs-all@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C564316A41F for ; Sat, 8 Oct 2005 11:16:50 +0000 (GMT) (envelope-from brutyn_nick@hotmail.com) Received: from hotmail.com (bay103-f17.bay103.hotmail.com [65.54.174.27]) by mx1.FreeBSD.org (Postfix) with ESMTP id 90FF543D46 for ; Sat, 8 Oct 2005 11:16:48 +0000 (GMT) (envelope-from brutyn_nick@hotmail.com) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Sat, 8 Oct 2005 04:16:48 -0700 Message-ID: Received: from 65.54.174.200 by by103fd.bay103.hotmail.msn.com with HTTP; Sat, 08 Oct 2005 11:16:48 GMT X-Originating-IP: [213.224.232.17] X-Originating-Email: [brutyn_nick@hotmail.com] X-Sender: brutyn_nick@hotmail.com From: "Nick Brutyn" To: cvs-all@freebsd.org Date: Sat, 08 Oct 2005 11:16:48 +0000 Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-OriginalArrivalTime: 08 Oct 2005 11:16:48.0529 (UTC) FILETIME=[C65E4810:01C5CBF9] Subject: Creating excel file with ruby on rails X-BeenThere: cvs-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: CVS commit messages for the entire tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Oct 2005 11:16:50 -0000 hey, i want to create a excel file with ruby on rails and send that file to the browser (excel file must be supporting all versions) this is what i have so fare, i cant send it to the server, anyone any sollutions 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 @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/timesheets.xls") version = Excel::VERSION # Preferred way to add a format f1 = wb.add_format(:color=>"black",:bold=>1,:italic=>true) f4 = Format.new(:num_format => "d mmm yyyy") f5 = Format.new(:num_format => 0x0f) wb.add_format(f4) wb.add_format(f5) ws1 = wb.add_worksheet("timesheets") #headers @header = ['Employee','Address','Zip','City','Duration','Start','Stop'] #headers afprinten op de 1ste rij 0.upto(@header.length - 1) do |i| ws1.write(0,i,@header[i], f1) end rij = 1 #de gegevens worden getoond vanaf de 2de rij #time entries afprinten for time_entry in @time_entries ws1.write(rij,0,time_entry.employee.last_name + " " + time_entry.employee.first_name) ws1.write(rij,1,time_entry.geotag.address1) ws1.write(rij,2,time_entry.geotag.zip) ws1.write(rij,3,time_entry.geotag.city) if time_entry.stop_time.nil? ws1.write(rij,4,"") ws1.write(rij,5,time_entry.start_time.strftime("%d/%m/%Y %H:%M")) ws1.write(rij,6,"") else ws1.write(rij,4,time_entry.duration) ws1.write(rij,5,time_entry.start_time.strftime("%d/%m/%Y %H:%M")) ws1.write(rij,6,time_entry.stop_time.strftime("%d/%m/%Y %H:%M")) end rij = rij + 1 end ws1.format_column(0..1,20,f1) ws1.format_column(2,5,f1) ws1.format_column(3..4,10,f1) ws1.format_column(5..6,15,f1) wb.close redirect_to :action=>"list_times" end