Home » Questions » Computers [ Ask a new question ]

How do I get Excel to import a CSV file with commas in some of the content fields?

How do I get Excel to import a CSV file with commas in some of the content fields?

How do I get Excel to import my CSV file?

Asked by: Guest | Views: 359
Total answers/comments: 6
bert [Entry]

"I just tried a quick test that replicated your problem.

I created a 1 line CSV in Word (which uses smart quotes) as test.csv
“123”,“4,5,6”
and it opened in Excel as you described.

Try replacing “ and ” with ""

Having played with your sample I notice that Excel does not like the spaces between fields

e.g. instead of

""20051"", """", ""2009 Sep 30 02:53:23"", ...

you want

""20051"","""",""2009 Sep 30 02:53:23"",...

a decent Regular Expression replacement should be able to handle it with

Find: |(""[^""]*"",) |
Replace: |\1|

(pipe characters for visual cues only)

Or simply modify the .Net code if you have access to it ;-)

Also, as Arjan pointed out, you may also need to convert the file from UTF-8 to ANSI to prevent cell A1 from containing the BOM and its surrounding qoutes.

I have come across the Catch 22 of ANSI encoded CSV not handling international characters and UTF encoded CSV not being propery handled by Excel; and not found a solution while mainting the CSV. If international character support is required, the XML (or native XLS) formats seem the only way to go—at the cost of simplicity."
bert [Entry]

You could also try CSVEd which is free.
bert [Entry]

"Just adding to the answers here: focus on the SPACES after the COMMAS in your CSV files. Excel does not like these if you have quoted fields in your data.

Excel likes (4 columns of data):

a, b, c, d

But does not like (3 columns of data):

a, ""b, c"", d

It does like (3 columns of data):

a,""b, c"",d"
"Just adding to the answers here: focus on the SPACES after the COMMAS in your CSV files. Excel does not like these if you have quoted fields in your data.

Excel likes (4 columns of data):

a, b, c, d

But does not like (3 columns of data):

a, ""b, c"", d

It does like (3 columns of data):

a,""b, c"",d"
bert [Entry]

"I ran across this problem today and also found a solution that worked for me.

My environment / context: I have a web page with some (form) questions that contain both double quotes and commas. Both the questions and the answers are pulled out of the database and written to an Excel file for reporting purposes.

I had the same problem described above: The questions that included both double quotes and commas were being split into multiple columns in Excel.

For my purposes, using two single quotes in place of a double quote did the trick.

--> on the website, two single quotes look like a double quote to site visitors

--> In the Excel file, again, two single quotes look like a double quote for users viewing the report data

I realize that this solution won't work for everyone, but hopefully it will help someone."
bert [Entry]

"I was able to do this using:

a,b,c,""=""""(1,2,3)""""""

which gives four columns:

| a | b | c | (1,2,3) |"
Hkytkv [Entry]

atorvastatin 80mg cheap <a href="https://lipiws.top/">atorvastatin 80mg sale</a> purchase atorvastatin sale