How should I escape commas and speech marks in CSV files so they work in Excel?

后端 未结 5 1168
说谎
说谎 2020-11-29 00:20

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

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 00:46

    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!

提交回复
热议问题