Importing CSV with line breaks in Excel 2007

前端 未结 23 2257
悲哀的现实
悲哀的现实 2020-11-29 20:49

I\'m working on a feature to export search results to a CSV file to be opened in Excel. One of the fields is a free-text field, which may contain line breaks, commas, quota

23条回答
  •  青春惊慌失措
    2020-11-29 21:32

    +1 on J Ashley's comment. I ran into this problem also. It turns out that Excel requires:

    • A newline character("\n") in the quoted string

    • A carriage return and newline between each row.

    E.g.

    "Test", "Multiline item\n
    multiline item"\r\n
    "Test2", "Multiline item\n
    multiline item"\r\n
    

    I used notepad ++ to delimit each row properly and to only use newlines in the string. Discovered this by creating multiline entries in a blank excel doc and opening the csv in notepad ++.

提交回复
热议问题