Display problem with to_csv

Hi all,

I need to export the document as csv file, i have exported
successfully, but the problem is not displayed as per my format, in csv
file the format is suffuled, i want the orderwise as how i have
mentioned in my query, please help me to come out in the order wise.
My coding 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’,
addr2 as ‘Business Street1’,addr3 as ‘Business Street2’,addr4 as
‘Business Street3’,
address_city as ‘Business City’,address_state as ‘Business
State’,address_postalcode
as ‘Business Postal Code’,c.c_name as ‘Business Country’ ,’’ as ‘Home
Street’,
‘’ as ‘Home Street 2’,’’ as ‘Home Street 3’,’’ as ‘Home City’,
‘’ as ‘Home State’,’’ as ‘Home Postal Code’,’’ as ‘Home Country’,
‘’ as ‘Other Street’,’’ as ‘Other Street 2’,’’ as ‘Other Street 3’,’’
as ‘Other City’,
‘’ as ‘Other State’,’’ as ‘Other Postal Code’,’’ as ‘Other Country’,’’
as ‘Assistants Phone’,
phone_fax as ‘Business Fax’,phone_work as ‘Business Phone’,
phone_mobile as ‘Business Phone 2’,’’ as ‘Callback’,’’ as ‘Car
Phone’,
phone_work as ‘Company Main Phone’,’’ as ‘Home Fax’,
phone_homeas ‘Home Phone’,
‘’ as ‘Home Phone 2’,’’ as ‘ISDN’,phone_mobile as ‘Mobile Phone’,’’
as ‘Other Fax’,
‘’ as ‘Other Phone’,’’ as ‘Pager’,’’ as ‘Primary Phone’,’’ as ‘Radio
Phone’,’’ as ‘TTY/TDD Phone’,
‘’ as ‘Telex’,’’ as ‘Account’,’’ as ‘Anniversary’,’’ as ‘Assistants
Name’,’’ as ‘Billing Information’,
‘’ as ‘Birthday’,’’ as ‘Categories’,’’ as ‘Children’, email1 as
‘E-mail Address’,email2 as ‘E-mail Display Name’,
‘’ as ‘E-mail 2 Address’,’’ as ‘E-mail 2 Display Name’,’’ as ‘E-mail 3
Address’,’’ as ‘E-mail 3 Display Name’,
‘’ as ‘Gender’,’’ as ‘Government ID Number’,’’ as ‘Hobby’,’’ as
‘Initials’,’’ as ‘Keywords’,
‘’ as ‘Language’,’’ as ‘Location’,’’ as ‘Mileage’,’’ as ‘Notes’,’’ as
‘Office Location’,
‘’ as ‘Organizational ID Number’,’’ as ‘PO Box’,’’ as ‘Private’,’’ as
‘Profession’,
‘’ as ‘Referred By’,’’ as ‘Spouse’,’’ as ‘User 1’,’’ as ‘User 2’,’’ as
‘User 3’,
‘’ as ‘User 4’,’’ as’Web Page’
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”)

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

expected output in excel file should come in the order wise as how i
have mentioned in the query.

  but at present, its coming like in a suffled order, like this in excel
file

Home Phone  E-mail Display Name  Office Location  Language  Home Street
Notes  Home Phone 2  Business Phone  Company Main Phone  Business State
User 4  Other State  Title  User 3  Business Phone 2  Account  Other
Street  Private  Profession  Radio Phone  User 2  Referred By  User 1
Location  Home State  Pager  Middle Name  Business City  Keywords
Business Country  Organizational ID Number  E-mail 3 Display Name
Department  Home Street 3  Home Postal Code  Gender  Home Street 2
Mileage  Business Street  Other Street 3  Job Title  Home Fax  Web Page
Business Fax  Other Street 2  Business Street3  Other Country  E-mail
Address  Business Street2  Home City  Other Fax  ISDN  First Name
Anniversary  Home Country  PO Box  TTY/TDD Phone  Business Street1
E-mail 3 Address  Car Phone  Other Postal Code  Government ID Number
E-mail 2 Address  Suffix  Assistants Phone  Spouse  Billing Information
Business Postal Code  Mobile Phone  Company  Other City  Callback  Telex
Birthday  Other Phone  Primary Phone  E-mail 2 Display Name  Children
Last Name  Assistants Name  Categories  Hobby  Initials


   if anyone knows how to do the order wise, please let me know as soon
as possible. Thanks in Advance.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs