Re: Importing/parsing CSV files
Re: Importing/parsing CSV files
- Subject: Re: Importing/parsing CSV files
- From: kai <email@hidden>
- Date: Wed, 13 Sep 2006 03:53:03 +0100
On 13 Sep 2006, at 02:03, T&B wrote:
Did you write this a while back, or garner it from somewhere else?
Neither. I cobbled it together today after reading one of your
earlier posts. (Not that my reading is *quite* that slow; I just
returned from a trip that kept me Mac-less for a while.) ;-)
--------
On 13 Sep 2006, at 02:27, Doug McNutt wrote:
Does this latest version take into account Excel's use of ,"", to
represent a cell that contains no characters but is not, in Excel's
terms, blank?
A blank would come out as ,,.
Right. When Excel exports data to CSV format, each row contains the
appropriate number of commas (even when fields are empty, or where
original cells might have been merged). Using the flavour of Tom's
original example, CSV data like this...
--------
"First Name,Last Name,Age,Phone
Mickey,Mouse,65,5555 5555
\"Huey, Dewey and Louie\",Duck,,
Daisy,\"Duck
formerly Chick\",62,\"5555 7777, ext 234\"
Donald,Duck,64,\"5555 7777, ext 235\""
--------
... would be parsed as:
--------
--> {{"First Name", "Last Name", "Age", "Phone"}, {"Mickey", "Mouse",
"65", "5555 5555"}, {"Huey, Dewey and Louie", "Duck", "", ""},
{"Daisy", "Duck
formerly Chick", "62", "5555 7777, ext 234"}, {"Donald", "Duck",
"64", "5555 7777, ext 235"}}
--------
So any empty fields are translated into empty strings in a list (as
illustrated by the "Huey, Dewey and Louie" example, above). If the
data was generated by an application that ignored empty fields (and
therefore didn't retain all the commas), the resulting list would be
correspondingly shorter:
--------
"First Name,Last Name,Age,Phone
Mickey,Mouse,65,5555 5555
\"Huey, Dewey and Louie\",Duck
Daisy,\"Duck
formerly Chick\",62,\"5555 7777, ext 234\"
Donald,Duck,64,\"5555 7777, ext 235\""
--------
--> {{"First Name", "Last Name", "Age", "Phone"}, {"Mickey", "Mouse",
"65", "5555 5555"}, {"Huey, Dewey and Louie", "Duck"}, {"Daisy", "Duck
formerly Chick", "62", "5555 7777, ext 234"}, {"Donald", "Duck",
"64", "5555 7777, ext 235"}}
--------
---
kai
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden