Question posted 2012 · +65 upvotes
I’m generating a CSV file (delimited by commas rather than tabs). My users will most likely open the CSV file in Excel by double clicking it. My data may contain commas and speech marks, so I’m escaping those as follows.
Reference, Title, Description
1, "My little title", "My description, which may contain ""speech marks"" and commas."
2, "My other little title", "My other description, which may also contain ""speech marks"" and commas."
As far as I know that’s always been the way to do it. Here’s my boggle: when I open this file in Excel 2010 my escaping is not respected. Speech marks appear on the sheet, and the comma causes new columns.
Accepted answer +136 upvotes
We eventually found the answer to this.
Excel will only respect the escaping of commas and speech marks if the column value is NOT preceded by a space. So generating the file without spaces like this…
Reference,Title,Description
1,"My little title","My description, which may contain ""speech marks"" and commas."
2,"My other little title","My other description, which may also contain ""speech marks"" and commas."
… fixed the problem. Hope this helps someone!
Top excel Q&A (6)
- Shortcut to Apply a Formula to an Entire Column in Excel +335 (2011)
- Convert xlsx to csv in linux command line +96 (2012)
- How to create a link inside a cell using EPPlus +50 (2011)
- IF statement: how to leave cell blank if condition is false ("" does not work) +44 (2013)
- T-SQL: Export to new Excel file +44 (2012)
- Generating CSV file for Excel, how to have a newline inside a value +41 (2009)
excel solutions on this site
— top 1%.