views:

156

answers:

1

When importing a CSV file into Excel, it only strips the double-quotes from the FIRST field on the line, but leaves them on all other fields. How can I force Excel to strip the quotes from ALL strings?

For instance, I have a CSV file:

"text1", "text2", "numeric1", "numeric 2"

"abc", "def", 123, 456

"abc", "def", 123, 456

"abc", "def", 123, 456

"abc", "def", 123, 456

I import it into Excel using Data > Import External Data > Import Data. I specify that the fields are delimited by commas, and that the text delimiter is the double-quote character.

Both the data preview and the actual Excel spreadsheet columns only strip the double-quotes from the first text field. All other text fields still have quotes around them. What's really strange is that Access is able to import this data correctly (i.e. strips quotes from every text field.

Note that this is NOT a matter of internal commas or quotes or escape characters.

This happens in Excel 2003 and Excel 2007.

+1  A: 

Remove all spaces before/after commas from the document to be imported.

DanM
Yup. Removing the commas fixed it completely. Now my question is; why on earth would the commas after the spaces make a difference? And why does Access import the data as expected?
Klay
@Klay, I think it has something to do with this (from http://en.wikipedia.org/wiki/Comma-separated_values): *In some CSV implementations, leading and trailing spaces or tabs, adjacent to commas, are trimmed. This practice is contentious and in fact is specifically prohibited by RFC 4180, which states, "Spaces are considered part of a field and should not be ignored."*...So, when you put spaces before the quote, your field is not technically surrounded with quotes, it's surrounded by a space and an end-quote.
DanM