Tony Bris

Q: Numbers does not import CSV files properly

Using Numbers v 3.6.2 under OS X El Capitan v 10.11.6 CSV files are not imported correctly. A file with 8 columns appears in Numbers as two columns with the first containing data from 7 columns and the second containing the data from the remaining column. This does not happen with Numbers v 2.1 which I have on another Mac running OS X v10.6.8

 

Alright I know one answer would be to always to download to the latter Mac but I am trying to stop using this once all data that I need is available on the other, later, Mac.

 

If Apple could provide a program that does the job correctly why on earth can't a later version do the same, it's a basic requirement and I don't want to play around trying to sort it out I just want it to work as it ought to.

iMac (27 inch), OS X El Capitan (10.11.5)

Posted on Aug 24, 2016 4:36 AM

Close

Q: Numbers does not import CSV files properly

  • All replies
  • Helpful answers

  • by Wayne Contello,Helpful

    Wayne Contello Wayne Contello Aug 24, 2016 9:25 AM in response to Tony Bris
    Level 6 (18,960 points)
    iWork
    Aug 24, 2016 9:25 AM in response to Tony Bris

    might be worth providing an example of the file, or, perhaps share the data... No-one here can change Numbers, we are all users like you.  So the only options we have are to provide solutions using what already exists, or to work around issues by other means.

     

    You can always provide feedback to pole using the menu item "Numbers > Provide Numbers Feedback"

  • by Tony Bris,

    Tony Bris Tony Bris Aug 24, 2016 9:24 AM in response to Wayne Contello
    Level 1 (19 points)
    Desktops
    Aug 24, 2016 9:24 AM in response to Wayne Contello

    Thanks for the reply. Unfortunately I can't share the data because it is a download from my bank. I appreciate that Numbers can't be changed (except by Apple!) but I wonder whether anyone else has had a similar problem and devised a quick work around. I'm pretty confident that my bank hasn't changed the format of their CSV file, after all it opens in an earlier version of Numbers as it has always done which makes me suspect the later version. I'll probably see if version 2.1 of Numbers will run on El Capitan.

  • by SGIII,Helpful

    SGIII SGIII Aug 24, 2016 11:56 AM in response to Tony Bris
    Level 6 (10,622 points)
    Mac OS X
    Aug 24, 2016 11:56 AM in response to Tony Bris

    Tony Bris wrote:

     

    Unfortunately I can't share the data because it is a download from my bank.

     

    Hi Tony,

     

    Just open a copy of the download file from your bank, open in Textedit (in your applications folder), delete all but the first few lines, change a few names and numbers if necessary to disguise them, and paste into a post here.  That should take less than a minute, and can save you (and us) a lot of time as it will immediately show the exact format (csv comes in a lot of flavors).  Almost certainly there are easier ways to solve your problem than fooling around with a 7-year old version of Numbers.

     

    SG

  • by Wayne Contello,

    Wayne Contello Wayne Contello Aug 24, 2016 11:37 AM in response to Tony Bris
    Level 6 (18,960 points)
    iWork
    Aug 24, 2016 11:37 AM in response to Tony Bris

    I still use Number '09 to open quicken exchange format file (QXF).  This was dropped in going from Numbers 2.x to 3.x.

     

    This is the primary reason I keep Numbers 2.x around.

  • by Tony Bris,

    Tony Bris Tony Bris Aug 25, 2016 7:27 AM in response to SGIII
    Level 1 (19 points)
    Desktops
    Aug 25, 2016 7:27 AM in response to SGIII

    Thanks, have attached a .txt file as requested. Hope there is a solution

     

    Date, Type, Description, Value, Balance, Account Name, Account Number

     

    27/06/2016,DPC,"'CALL“,-xx.00,xx.00,”’FRED ZZ&YY”,”’123456-12345678”,

    29/06/2016,CHQ,”’123456”,-xx.00 123456,”FRED ZZamp;YY”,”’123456-12345678”,

    30/06/2016,BAC,”’JIM”,xx.00,xx.200,”’FRED ZZ&YY”,”’123456-12345678”,

    30/06/2016,CHQ,”’123456”,-xx.00,xx.00,”’FRED ZZ&YY”,”’123456-12345678”

  • by SGIII,

    SGIII SGIII Aug 25, 2016 9:14 AM in response to Tony Bris
    Level 6 (10,622 points)
    Mac OS X
    Aug 25, 2016 9:14 AM in response to Tony Bris

    That format looks a little strange. For example some of the quotation marks are "straight" and some are "curly".  That could have happened in the copy-pasting process. CSV is not a "strict" standard and there are endless little variations that can cause problems.

     

    Assuming there are no commas within a column in your download (e.g. descriptions that have commas in them) then the simple script below should fix the file so you can paste the values directly into Numbers. No AppleScript knowledge needed to use the script, just copy-paste.

     

    1. Copy-paste the script below into Script Editor (in Applications > Utilities).
    2. If you have not used scripts on your machine make sure the box by Script Editor.app is checked at System Preferences > Security & Privacy > Privacy > Accessibility. You only need to do this once.
    3. Click the triangle 'run' button and navigate to the downloaded csv file, which is assumed to have a csv extension.
    4. Click once in a Numbers cell and command-v to paste in the values.

     

    If this doesn't quite do the right thing then just post results and the script can be adjusted. Once it's working you can just use the script every time you do a download. You can turn it into a menu pick. Because it places the results on the clipboard for pasting wherever you want it in an existing Numbers document it may be a little easier than having to open the csv file in a new Numbers document each time.

     

    SG

     

    set inText to read (choose file with prompt "Choose csv file" of type "csv") as «class utf8»

    set outText to substitute({"“", "”", "‘", "’", ",", "&"}, {"", "", "", "", tab, "&"}, inText)

    set the clipboard to outText

    display notification "Click once in a Numbers cell and command-v to paste"

     

    on substitute(s, r, t)

      repeat with i from 1 to count s

      set text item delimiters to s's item i

      set t to t's text items

      set text item delimiters to r's item i

      set t to t as text

      end repeat

      return t

    end substitute

  • by Tony Bris,

    Tony Bris Tony Bris Sep 1, 2016 6:19 AM in response to SGIII
    Level 1 (19 points)
    Desktops
    Sep 1, 2016 6:19 AM in response to SGIII

    Sorry about the delay in response but I have been doing further investigation. First in relation to the separators the field separators are the lower single quotation marks. However some lower single quotation marks relate to use within a field in which case the whole contents of the field are included within double quotes but also within the single quotes which are used as the field separator. Just to confuse the issue further there are other fields which contain a semi-colon ; and this field is also enclosed within double quotes. What I can say is that neither of the two money fields  are enclosed in double quotes which suggests that they are effectively defined as a numeric field although fields 7 and 8 contain numbers although they are not numeric in the sense that they are not calculated fields. However to muddy the water further the Transaction field is not within double quotes either. Finally why are some double quotes effectively treble quotes with some straight and some curly. Again there seems to be a reason for this as they are in the same place in all records but what do they mean?

     

    Thank you very much for your input and possible solution but I have not yet tried your script. Apple have been in touch with me having picked up the problem from this thread and asked several questions and also requested a CSV file which I have sent to them. So I am hopeful that they may be able to solve the problem. If not I will definitely try the script.

  • by SGIII,Solvedanswer

    SGIII SGIII Sep 1, 2016 6:56 AM in response to Tony Bris
    Level 6 (10,622 points)
    Mac OS X
    Sep 1, 2016 6:56 AM in response to Tony Bris

    Trying the script will take you less than a minute.  Copy-paste-click and you're done.  Why not give it a try?  It's really easy to try and it might let you get work done in the meantime.  It works on the sample you posted.

     

    Note that the sample you provided here also confuses Excel, which is really good at parsing CSV files.  That is a pretty good indication that something went wrong with the file.

     

    CSV (character-separated-values) is a loose standard. If the delimiter character is a comma, straight double quotes are needed around values that include a comma within them.  If the delimiter character is a semicolon ; quotes are needed around values that include a ; within them. Including quotes around a value even when not needed typically doesn't confuse parsers.

     

    The quotes do typically have to be straight, not curly. How you ended up with curly quotes in your file isn't clear. It could be you opened it in an app, Numbers or TextEdit or many others on the Mac, where you  Smart Links turned on in the Edit > Substitutions menu.  Best to turn that off when working with CSV files.

     

    Screen Shot 2016-09-01 at 9.50.28 AM.png

     

    Anyway, give the script a quick try.  It might do the trick.

     

    SG

  • by Tony Bris,

    Tony Bris Tony Bris Sep 1, 2016 11:09 AM in response to SGIII
    Level 1 (19 points)
    Desktops
    Sep 1, 2016 11:09 AM in response to SGIII

    Bingo!!

    It worked a treat. Many, many thanks and also thanks for pushing me to do it when I said I would wait for Apple's response. I hope that they can solve it eventually but your solution is a very valuable, but hopefully short term, solution.

  • by SGIII,

    SGIII SGIII Sep 1, 2016 11:28 AM in response to Tony Bris
    Level 6 (10,622 points)
    Mac OS X
    Sep 1, 2016 11:28 AM in response to Tony Bris

    Hi Tony,

     

    Fantastic to hear it worked.  Now at least you can carry on while awaiting a more permanent solution. And also check out the Smart Links setting in any apps you use to open the downloaded file. That could be a source of some of the problems.  Thanks for the green check!

     

    SG

  • by SGIII,

    SGIII SGIII Sep 2, 2016 7:01 PM in response to Tony Bris
    Level 6 (10,622 points)
    Mac OS X
    Sep 2, 2016 7:01 PM in response to Tony Bris

    Tony,

     

    You probably already figured it out, but a couple of posts up I meant to write turn off 'Smart Quotes' in the Edit > Substitutions menu.  I wrote 'Smart Links' by mistake.  It's 'Smart Quotes' that can introduce "curly" quotes that can be a problem in CSV files.

     

    SG