Importing CSV with line breaks in Excel 2007

前端 未结 23 2191
悲哀的现实
悲哀的现实 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:10

    Excel is incredibly broken when dealing with CSVs. LibreOffice does a much better job. So, I found out that:

    • The file must be encoded in UTF-8 with BOM, so consider this for all the points below
    • The best result, by far, is achieved by opening it from File Explorer
    • If you open it from within Excel there are two possible outcomes:
      • If it has only ASCII characters, it will most likely work
      • If it has non-ASCII characters, it will mess your line breaks
    • It seems to be heavily dependent on the decimal separator configured in the OS's regional settings, so you have to select the right one
    • I would bet that it may also behave differently depending on OS and Office version

提交回复
热议问题