Hi all, i am exporting the file by using to_csv, but its coming as unordered rather than my expected output, if i check in the database, its working fine, but in the excel sheet it shows in the unordered,so please let me knoe, how to show orderly in the excel sheet by using to_csv. @report_data=EdiaUserContact.find_by_sql( "SELECT '''' as ''Title'', `fname` as ''First Name'','''' as ''Middle Name'', `lname` as ''Last Name'','''' as ''Suffix'',m.member_company_name as ''Company'' , `department` as ''Department'',`title` as ''Job Title'', `addr1` as ''Business Street'',....") respond_to do |wants| wants.csv do render :text => @report_data.to_csv response.headers[''Content-Type''] = ''text/csv; charset=iso-8859-1; header=present'' response.headers[''Content-Disposition''] = "attachment; filename=contacts.csv" end end please let me know as soon as possible, thanks in advance -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
John Tsombakos
2007-Oct-16 13:23 UTC
Re: how to arrange the field in excel by using to_csv
On 10/16/07, Vidya Vidya <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi all, > > i am exporting the file by using to_csv, but its coming as unordered > rather than my expected output, if i check in the database, its working > fine, but in the excel sheet it shows in the unordered,so please let me > knoe, how to show orderly in the excel sheet by using to_csv. > > @report_data=EdiaUserContact.find_by_sql( > "SELECT '''' as ''Title'', > `fname` as ''First Name'','''' as ''Middle Name'', > `lname` as ''Last Name'','''' as ''Suffix'',m.member_company_name as > ''Company'' , > `department` as ''Department'',`title` as ''Job Title'', `addr1` as > ''Business Street'',....") > > respond_to do |wants| > wants.csv do > render :text => @report_data.to_csv > response.headers[''Content-Type''] = ''text/csv; charset=iso-8859-1; > header=present'' > response.headers[''Content-Disposition''] = "attachment; > filename=contacts.csv" > end > end > > please let me know as soon as possible, thanks in advance > --Errr... if you want the data sorted, you have to sort it - it''s not going to magically be in the order you want! Throw an ORDER BY clause in your SQL. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
hi, Thanks for your Reply, but i already written order by in query itself, if i check in database it had come as right, but in the excel sheet it came as unordered, i don''t know why? please let me know, if anybodies knows. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2007-Oct-17 09:04 UTC
Re: how to arrange the field in excel by using to_csv
On 17 Oct 2007, at 05:37, Vidya Vidya wrote:> > hi, > > Thanks for your Reply, but i already written order by in query > itself, > if i check in database it had come as right, but in the excel sheet it > came as unordered, i don''t know why? please let me know, if anybodies > knows. >Are you talking about the ordering of the rows or of the columns? Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
hi, thanks for ur reply, i am talking about both colums and rows, see, how the output came in my excel sheet, Job Title Suffix First Name Company Title Middle Name dfjh HEGF OddWorlders fghfdgh yyy dfgdfg OddWorlders but my expected output is Title First Name Middle Name Last Name Suffix Company Job Title Business Street fghfdgh HEGF OddWorlders dfjh dfgdfg OddWorlders yyy like this i want as how i specified the order in the query. my qurey is @report_data=EdiaUserContact.find_by_sql( "SELECT '''' as ''Title'', `fname` as ''First Name'','''' as ''Middle Name'', `lname` as ''Last Name'','''' as ''Suffix'',m.member_company_name as ''Company'' , `department` as ''Department'',`title` as ''Job Title'', `addr1` as ''Business Street'' FROM `edia_user_contacts`, edia_members m, edia_countries c WHERE m.id=''#{session[:member_id]}'' and user_member_id in (select partner_id from edia_member_partners where company_id = ''#{session[:member_id]}'') and c.id=`address_country`") -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2007-Oct-17 09:28 UTC
Re: how to arrange the field in excel by using to_csv
On 17 Oct 2007, at 10:20, Vidya Vidya wrote:> > hi, thanks for ur reply, i am talking about both colums and rows, > > see, how the output came in my excel sheet, > > Job Title Suffix First Name Company Title Middle Name > dfjh HEGF OddWorlders fghfdgh > yyy dfgdfg OddWorlders > > > but my expected output is > > Title First Name Middle Name Last Name Suffix Company Job Title > Business Street > fghfdgh HEGF OddWorlders dfjh > dfgdfg OddWorlders yyy >Attributes of an AR object don''t have an order, so you need to specify it explicity when you call to_csv. As per the docs for to_csvm you can do this with the :order or :only options Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
sorry, i couldn''t understand clearly, could you please can you explain little bit clear? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2007-Oct-17 09:47 UTC
Re: how to arrange the field in excel by using to_csv
On 17 Oct 2007, at 10:42, Vidya Vidya wrote:> > sorry, i couldn''t understand clearly, could you please can you explain > little bit clear?Read the docs for to_csv http://svn.integralserver.com/plugins/to_csv/README> -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
hi, i read the doc file, but i don''t where i set the order in the coding, could you please can you tell this, how to do? where i should set the order. respond_to do |wants| wants.csv do render :text => @report_data.to_csv response.headers[''Content-Type''] = ''text/csv; charset=iso-8859-1; header=present'' response.headers[''Content-Disposition''] = "attachment; filename=contacts.csv" end end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, Any body, please let me know, where i should set my options as order on the above coding? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Again... read the docs. http://svn.integralserver.com/plugins/to_csv/README :order - Array of columns in explicit order so @foo.to_csv(:order=>[:title:, :first_name, :middle_name, :last_name,:suffix, :company, :job_title, :business, :street]) To be successful with Rails, learn how to not only read but interpret the documentation. All of this code is open source so even if the docs aren''t clear, you should be able to open the source code and see what it''s doing. A wise developer once said that you shouldn''t use any code unless you understand how it works. On 10/17/07, Vidya Vidya <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hi, > > Any body, please let me know, where i should set my options as order > on the above coding? > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Brian Hogan Thanks for you advise, actually i have opened the opend source code also, but still my expected anwser is not coming, i have passed the parameters like as you have mentioned on the above, but while running no reflection in the code, the same output only coming -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---