CSV::Writer... Using tabs instead of commas (or creating excel file using tabs to seperate data)

J

John Kopanas

I want to create an excel file from data I get from my DB but since
some of my fields contain commas in them I was hoping I can use
CSV::Writer but instead of having the default of commas seperate data
I could use tabs? Any have any suggestions on what the sexiest way to
do this is?

--
John Kopanas
(e-mail address removed)

http://www.kopanas.com
http://www.cusec.net
http://www.soen.info
 
C

ChrisH

I want to create an excel file from data I get from my DB but since
some of my fields contain commas in them I was hoping I can use
CSV::Writer but instead of having the default of commas seperate data
I could use tabs? Any have any suggestions on what the sexiest way to
do this is?

--
John Kopanas
(e-mail address removed)

http://www.kopanas.comhttp://www.cusec.nethttp://www.soen.info

A quick look at the CSV docs indicates its easy to specify the
character to use as a field separator
(http://www.ruby-doc.org/stdlib/libdoc/csv/rdoc/classes/CSV/
Writer.html) Hint: look for 'fs'

If you want to avoid the intermediate CSV files you could use OLE to
drive Excel, or Spreadsheet
(http://rubyspreadsheet.sourceforge.net/) to create the file (even if
Excel is not installed).

Cheers
Chris
 
G

Gregory Brown

it is okay to have commas in CSV fields.
require 'rubygems' => true
require 'fastercsv' => true
%w[ foo,bar baz ].to_csv
=> "\"foo,bar\",baz\n"

CSV in the stdlib should handle this correctly as well.

So that having been said, possibly the sexiest way to do SQL to CSV is
via Ruport. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top