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

Discussion in 'Ruby' started by John Kopanas, Jan 29, 2007.

  1. John Kopanas

    John Kopanas Guest

    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


    http://www.kopanas.com
    http://www.cusec.net
    http://www.soen.info
    John Kopanas, Jan 29, 2007
    #1
    1. Advertising

  2. John Kopanas

    ChrisH Guest

    On Jan 29, 11:22 am, "John Kopanas" <> wrote:
    > 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
    >
    >
    > 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
    ChrisH, Jan 29, 2007
    #2
    1. Advertising

  3. On 1/29/07, ChrisH <> wrote:
    > On Jan 29, 11:22 am, "John Kopanas" <> wrote:
    > > 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?


    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. :)
    Gregory Brown, Jan 29, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AviraM
    Replies:
    2
    Views:
    6,359
    Manish Pandit
    Sep 28, 2006
  2. moondaddy
    Replies:
    2
    Views:
    577
    Steven Cheng[MSFT]
    Oct 16, 2006
  3. DaVinci
    Replies:
    1
    Views:
    564
    Piotr Kobzda
    Oct 5, 2006
  4. Henri
    Replies:
    1
    Views:
    375
    Henri
    Jul 13, 2004
  5. John Kopanas
    Replies:
    2
    Views:
    117
Loading...

Share This Page