Thread: Question about exporting to CSV file

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    1

    Question about exporting to CSV file

    I am developing a program to export text into CSV format.
    My text format is like 001, 0012, 000173.
    If I use the following code segment:

    ofstream tmp ("book1.csv");
    tmp<<"001";
    tmp<<",";
    tmp<<"0012";
    tmp.close();

    and open the this file in Excel, the cell will be displayed
    1 and 12 not 001 and 0012l.
    How can I modify the code to let the Excel not convert the text
    format?
    Thanks!

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    The problem is inside Excel, not your program. In Excel, use menu item Data-->Import External Data->Import and select the file to be imported. In Step 1 of the Import Wizard leave the defaults value, in Step 2 change "Text Qualifier" to None. Then click Finish.

    The file will need the quotes, like this
    Code:
    "001","002","003"
    To achieve that the quotes have to be escaped, like this
    Code:
    cout << "\"001\""
    Last edited by Ancient Dragon; 10-11-2005 at 04:11 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. A question about file streams.
    By Lawn Gnomusrex in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2008, 06:05 AM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM