Please help with a CSV to Numbers format issue

How do I get numbers to open a csv file that has a column of phone numbers and stop the imported data from dropping the leading zero? I have a csv file where one of the data columns has telephone numbers in it and is formatted as text in Excel. However when I either copy and paste this into Numbers, or just open the file in Numbers it automatically changes the field format of the column and then the leading zero of the phone number is removed. How do I stop this happening?

iMac, OS X Yosemite (10.10.3), 27"

Posted on Nov 4, 2015 10:42 AM

Reply
9 replies

May 15, 2017 7:13 AM in response to SGIII

Maybe not usually, but it does with Numbers 4.1.1. See attached, the UPC field now has a leading apostrophe.


I've tried formatting the UPCs in double quotes, ie "012345678901" but it drops the leading zero.

I've tried putting an apostrophe in the quotes, ie "'012345678901" but it shows the leading apostrophe.

I've tried using an apostrophe without quoted, ie '012345678901 but it shows the leading apostrophe.


Numbers is fine for 95% of the tasks I use it for, but terrible at handling UPCs. I won't switch to open office of libre office just because of that. There's got to be something I'm doing wrong when creating the CSV.


User uploaded file

May 15, 2017 7:57 AM in response to Senator Casey

I see. You're adding the ' into the CSV file itself, before importing it to Numbers.


If you do a lot of importing of CSV files with leading 0s then you may find this CSV to Tabs on Clipboard Automator Service (Dropbox download) helpful. No need to add ' to the file.


To use it, you navigate in Finder (not Numbers) to the CSV file, right-click and choose CSV to Tabs on Clipboard from the Numbers > Services menu. Answer the prompt. Then click once in a cell in an existing Numbers table, and command-v or Edit > Paste and Match Style to paste. If before pasting you have first formatted the column receiving the UPCs as Text, then the leading 0s should be preserved.


One-time installation consists of double-clicking the downloaded .workflow package and giving permission at System Preferences > Security & Privacy. Also make sure Automator.app is checked at System Preferences > Security & Privacy > Privacy > Accessibility.


This sounds more complicated than it is. In a few seconds you're done.


Also you might leave feedback with Apple at Numbers > Provide Numbers Feedback in your menu pointing out that leading "zeros" are dropped on CSV import.


SG

Nov 4, 2015 12:29 PM in response to bespoke.computing

bespoke.computing wrote:


How do I get numbers to open a csv file that has a column of phone numbers and stop the imported data from dropping the leading zero?


Try explicitly formatting the column(s) in Numbers as Text (rather than leaving them as Automatic), then copy-paste from Excel. Usually that works. If that still results in dropped leading zeros, try formatting all the columns in Numbers as Text first. You can also try Edit > Paste and Match Style if you're still having trouble.


Just opening a CSV file seems to always drop the leading zeros.


SG

Nov 5, 2015 6:55 AM in response to bespoke.computing

I suggest you report this problem to Apple on this via Number > Provide Numbers Feedback in your menu.


Meanwhile, it looks as if you your best bet is to restore the leading "zeros" after importing or pasting to Numbers.


One way to do that is via a script like the one below. It's easy to use.


  1. Copy-paste the script into Script Editor (in Applications > Utilities).
  2. Adjust the target length in the first line of the script to the length of your phone numbers (including the leading zeros).
  3. Insert a new column in Numbers and explicitly format its cells as Text.
  4. Select the cells in the "old" column in Numbers that contain the numbers you need to "fix".
  5. With those cells selected click the triangle 'run' button in Script Editor.
  6. Click once in the top cell of the new column in Numbers where you want the "fixed" values.
  7. Command-v or Edit > Paste and Match Style to paste the "fixed" numbers with the leading zeros restored.
  8. If all is well, delete the "old" column.


At first glance this looks complicated, but actually it's just a few clicks. There are also ways to restore the leading zeros with a formula, but that takes more work.


SG



property tgtLength : 10 -- change this as needed

tell application "Numbers"

tell front document to tell active sheet

tell (first table whose selection range's class is range)

set pasteStr to ""

repeat with c in selection range's cells

set paddedNum to "00000000" & c's value

set pasteStr to pasteStr ¬

& my strRight(paddedNum, tgtLength) & return

end repeat

end tell

end tell

end tell

set the clipboard topasteStr

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


to strRight(s, n)

try

return s's text -n thru -1

on error

return s

end try

end strRight

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Please help with a CSV to Numbers format issue

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.