0

I wrote the output of a python code to a csv file. The output needs to contain newlines inside, so I wrote '\n' where I needed them. However, when I open this cvs file in Excel, I see no newlines and the character '\n' is printed instead. I tried '\r\n' too but I doesn't work.

"chart_num, weekday, average, std_dev \r\n 214, 0, 2726, 658"

The above string is part of the csv file. How can I change the row in excel where '\r\n' exists?

  • Why are there quotes around the whole line? Shouldn't the individual columns be quoted (expecially the one with the newline)? – Thilo Aug 19 '15 at 03:11
  • Show your code. I can't reproduce. I opened a file and used `write` to send the string (with just \n) to the file. Saved it as a csv file, and had no problem when I subsequently opened it in Excel. – John Coleman Aug 19 '15 at 03:17

2 Answers2

0

You should try to output "=CHAR(13)" instead of "\r\n" which is the ASCII code for carriage return. Remember that you might use that by concatenating it with strings. Make the output "Excel readable" so to speak. And remember to mark the question as answered ;)

Raul Reyes
  • 453
  • 1
  • 4
  • 12
0

Maybe using '\r' character solves problem

mhbashari
  • 482
  • 3
  • 16