+ Reply to Thread
Results 1 to 4 of 4

Parsing CSV data incorrectly

Hybrid View

Datagrunt Parsing CSV data incorrectly 12-10-2009, 03:12 PM
martindwilson Re: Parsing CSV data... 12-10-2009, 05:11 PM
dominicb Re: Parsing CSV data... 12-10-2009, 05:12 PM
Datagrunt Re: Parsing CSV data... 12-10-2009, 06:04 PM
  1. #1
    Registered User
    Join Date
    11-18-2009
    Location
    Bay Area
    MS-Off Ver
    Excel 2007
    Posts
    6

    Parsing CSV data incorrectly

    I have a script I am running that outputs CSV files. If I open it in notepad++, everything is parsed correctly. Values with commas are protected within the quotes that are added in the script. However, Excel does not recognize the quotes and it wants to parse the data at every comma. Has anyone else had this problem?

    Thank you,
    Chris

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Parsing CSV data incorrectly

    an example please
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile Re: Parsing CSV data incorrectly

    Good evening Datagrunt
    Quote Originally Posted by Datagrunt View Post
    I have a script I am running that outputs CSV files. If I open it in notepad++, everything is parsed correctly. Values with commas are protected within the quotes that are added in the script. However, Excel does not recognize the quotes
    Are you wanting to create the .csv files without quotes? What code are you using at the moment? Are you using Save As ... .csv, or are you using the Write# / Print# commands. If the former, you will need to use the latter, if the latter, you will need to use Print# command, as Write# will put each discrete set of data within quotes.

    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  4. #4
    Registered User
    Join Date
    11-18-2009
    Location
    Bay Area
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Parsing CSV data incorrectly

    I'm working in Java and I resolved this through a hack:

    This is an Adobe script for extracting XMP information from files. The script originally saved it as a CSV file but it wouldn't parse correctly in Excel.

    I modified the script so that it wouldn't add quotes to the either the column headers or the values. I also changed the delimiter to a semi-colon (and you can choose any character you like, it doesn't have to be a semi-colon). When I open the file in Excel, I simply to a text to column using the semi-colon as the delimiter. Everything is then parsed correctly.

    for ( var i = 0; i < mdItems.length; i++ ) {
                        if ( i == 0 ) {
                            theRecord += ';' + mdItems[ i ].element.property + '';
                        } else {
                            theRecord += '; ' + mdItems[ i ].element.property + '';
    
    and...
    
             if ( a == 0 ) {
                                theRecord += ';' + val + '';
                            } else {
                                theRecord += '; ' + val + '';
                            }
    Last edited by dominicb; 12-11-2009 at 03:22 AM. Reason: Code tags added

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1