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

后端 未结 5 1169
说谎
说谎 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:48

    Below are the rules if you believe it's random. A utility function can be created on the basis of these rules.

    1. If the value contains a comma, newline or double quote, then the String value should be returned enclosed in double quotes.

    2. Any double quote characters in the value should be escaped with another double quote.

    3. If the value does not contain a comma, newline or double quote, then the String value should be returned unchanged.

提交回复
热议问题