# Convert data as CSV problem

**URL:** <https://www.ruby-forum.com/t/convert-data-as-csv-problem/92894>\
**Category:** Rails\
**Created:** [April 25, 2007, 2:22pm UTC](https://www.ruby-forum.com/t/convert-data-as-csv-problem/92894 "2007-04-25T14:22:17Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [April 25, 2007, 2:22pm UTC](https://www.ruby-forum.com/t/convert-data-as-csv-problem/92894/1 "2007-04-25T14:22:17Z")

</div>

hi all,

I want to convert my data as CSV file. just i used simple coding, i  
didn’t use fastercsv, because i installed in my system, but i couldn’t  
see where it install, if i run also , it said there is no fastercsv  
file. actaully i don’t know how to use that.

so now i used simple code is, but in this csv file is downloaded , by  
its coming with all HTML tags, even i didn’t use any html tags. so i  
want to know how to avoid this. please any one help me. thanks in  
advance.

in controller:

## def report @partner=Code.find(:all) response.headers[‘Content-Type’] = ‘text/csv; charset=iso-8859-1; header=present’ response.headers[‘Content-Disposition’] = ‘attachment; filename=report.csv’ end

in rhtml:

Title,Value  
\<% @partners.each do |model| -%\>  
“\<%= model.member\_fname %\>”,\<%= model.member\_lname %\>  
\<% end -%\>

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [April 25, 2007, 2:43pm UTC](https://www.ruby-forum.com/t/convert-data-as-csv-problem/92894/2 "2007-04-25T14:43:55Z")

</div>

removed\_email\_address@domain.invalid wrote:

> I want to convert my data as CSV file. just i used simple coding, i

Check out this plugin:

[http://svn.integralserver.com/plugins/to\_csv/](http://svn.integralserver.com/plugins/to_csv/)

It does all the hard work for you.

Eric

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [April 25, 2007, 3:05pm UTC](https://www.ruby-forum.com/t/convert-data-as-csv-problem/92894/3 "2007-04-25T15:05:08Z")

</div>

Eric A. wrote:

> removed\_email\_address@domain.invalid wrote:
> 
> > I want to convert my data as CSV file. just i used simple coding, i
> 
> Check out this plugin:
> 
> [http://svn.integralserver.com/plugins/to\_csv/](http://svn.integralserver.com/plugins/to_csv/)
> 
> It does all the hard work for you.
> 
> Eric

hi,

thank u very much for your quick response. is there any other way  
instead of plugin. because i can’t install this in client server

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [April 25, 2007, 3:11pm UTC](https://www.ruby-forum.com/t/convert-data-as-csv-problem/92894/4 "2007-04-25T15:11:57Z")

</div>

removed\_email\_address@domain.invalid wrote:

> thank u very much for your quick response. is there any other way  
> instead of plugin. because i can’t install this in client server

Sure. Just do the same things this plugin does. I don’t understand why  
you cannot install the plugin? Rails plugins are installed with the  
project so if you can edit the project files you can install the plugin.

Eric

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [April 25, 2007, 9:10pm UTC](https://www.ruby-forum.com/t/convert-data-as-csv-problem/92894/5 "2007-04-25T21:10:16Z")

</div>

Here’s a simple example of using the CSV module, I’m fairly sure this  
comes with the standard distribution of Ruby:

require ‘csv’  
data = “”

CSV::Writer.generate(data) { |csv|  
csv \<\< ['data\_item1,‘data\_item2’]  
}

File.open(OUTPUT\_FILENAME, ‘w’) { |file| file \<\< data }

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [April 26, 2007, 7:02am UTC](https://www.ruby-forum.com/t/convert-data-as-csv-problem/92894/6 "2007-04-26T07:02:30Z")

</div>

DZ wrote:

> Here’s a simple example of using the CSV module, I’m fairly sure this  
> comes with the standard distribution of Ruby:
> 
> require ‘csv’  
> data = “”
> 
> CSV::Writer.generate(data) { |csv|  
> csv \<\< ['data\_item1,‘data\_item2’]  
> }
> 
> File.open(OUTPUT\_FILENAME, ‘w’) { |file| file \<\< data }

hi,

for this csv writer , have i to install anything, or simple this code  
only will work. can u say please

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [April 26, 2007, 10:30am UTC](https://www.ruby-forum.com/t/convert-data-as-csv-problem/92894/7 "2007-04-26T10:30:25Z")

</div>

I heard active\_record extensions have a great .to\_csv method, is that  
the same as the CSV plugin mentioned above?

On Apr 26, 7:11 am, “François Beausoleil”

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [April 26, 2007, 7:12am UTC](https://www.ruby-forum.com/t/convert-data-as-csv-problem/92894/8 "2007-04-26T07:12:00Z")

</div>

Hi !

2007/4/25, removed\_email\_address@domain.invalid  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I want to convert my data as CSV file. just i used simple coding, i  
> didn’t use fastercsv, because i installed in my system, but i couldn’t  
> see where it install, if i run also , it said there is no fastercsv  
> file. actaully i don’t know how to use that.

You might want to read my blog post on just this topic:  
[http://blog.teksol.info/articles/2006/03/23/returning-csv-data-to-the-browser](http://blog.teksol.info/articles/2006/03/23/returning-csv-data-to-the-browser)

## Hope that helps !

François Beausoleil  
[http://blog.teksol.info/](http://blog.teksol.info/)  
[http://piston.rubyforge.org/](http://piston.rubyforge.org/)

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [April 26, 2007, 4:43pm UTC](https://www.ruby-forum.com/t/convert-data-as-csv-problem/92894/9 "2007-04-26T16:43:47Z")

</div>

I checked and this is part of the standard library.

[http://www.ruby-doc.org/stdlib/libdoc/csv/rdoc/index.html](http://www.ruby-doc.org/stdlib/libdoc/csv/rdoc/index.html)

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [April 26, 2007, 10:40am UTC](https://www.ruby-forum.com/t/convert-data-as-csv-problem/92894/10 "2007-04-26T10:40:41Z")

</div>

FranÃ§ois Beausoleil wrote:

> Hi !
> 
> 2007/4/25, removed\_email\_address@domain.invalid  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > I want to convert my data as CSV file. just i used simple coding, i  
> > didn’t use fastercsv, because i installed in my system, but i couldn’t  
> > see where it install, if i run also , it said there is no fastercsv  
> > file. actaully i don’t know how to use that.
> 
> You might want to read my blog post on just this topic:  
> [http://blog.teksol.info/articles/2006/03/23/returning-csv-data-to-the-browser](http://blog.teksol.info/articles/2006/03/23/returning-csv-data-to-the-browser)
> 
> ## Hope that helps !
> 
> Franç¯©s Beausoleil  
> [http://blog.teksol.info/](http://blog.teksol.info/)  
> [http://piston.rubyforge.org/](http://piston.rubyforge.org/)

hi,

i saw ur link, actually i followed this link only the second step. i  
got the answer. but it shows full of html coding in excel sheet. i want  
to show only anser instead of html tags.

and now i am going to try this first step also. for the have we  
install CSV:WRITER , or we can use like this.

```
     Thanks for ur help

```
