Share via

Importing CSV with line breaks

Reported
Anonymous
2016-01-05T17:46:19+00:00

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, quotations, etc. In order to counteract this, I have wrapped the field in double quotes (").

However, when I import the data into Excel 2007, set the appropriate delimiter, and set the text qualifier to double quote, the line breaks are still creating new records at the line breaks, where I would expect to see the entire text field in a single cell.

Here's a quick file I wrote by hand to reproduce the problem.

ID,Name,Description

"12345","Smith, Joe","Hey.

My name is Joe."

When I import this into Excel 2007, I end up with a header row, and two records. Note that the comma in "Smith, Joe" is being handled properly. It's just the line breaks that are causing problems.

I've also tried replacing CR/LF (\r\n) with just CR (\r), and again with just LF (\n), but no luck.

Has anyone else encountered this behavior, and if so, how did you fix it?

Steps to reproduce:

  1. Open the CSV with the content above in the excel
  2. Select the first column(column A)
  3. Click on Text to Columns
  4. Choose the Delimited option
  5. Select comma(,) as text delimiter
  6. Select quotes (") as text qualifier
  7. Click in Finish
Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2016-02-28T18:45:14+00:00

    Download LibreOffice, it imports CSV with line breaks out-of-the-box!

    0 comments No comments