Question

Locked

save .csv with newline character

By sanjeev.sircar ·
i'm creating a .csv file on the fly, thus am enclosing all the data within double quotes.
how to put in a newline character is the problem. for eg:-
i tried the following -

"header1","header2","header3"\n"data1","data2","data3"\n"data11","data22","data33"

and

"header1","header2","header3 \n"\r\n "data1","data2","data3 \n"\r\n "data11","data22","data33"

so that the output looks like

header1 header2 header3
data1 data2 data3
data11 data22 data33

thanks a lot for your help

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

I don't quite understand what you are asking ...

by OldER Mycroft In reply to save .csv with newline ch ...

Because whether you acheive a specific layout or not, this is still a .csv file which in itself doesn't support formats.

It is only ever supposed to be a .csv file.

Collapse -

Have you tried carriage return and line feed?

by ThumbsUp2 In reply to save .csv with newline ch ...

Try using \cr and \lf

.

Collapse -

Explain "on the fly"

by Bizzo In reply to save .csv with newline ch ...

Ultimately, for your csv file to output what you want, and to be interpreted correctly (by Excel say), then the csv file itself should only contain:

"header1","header2","header3"
"data1","data2","data3"
"data11","data22","data33"


If you can explain how you are creating the csv file, we might be able to help further.

Collapse -

No need for /n

by LarryD4 In reply to save .csv with newline ch ...

How are you creating the CSV?
Programmatically or by hand with a text file?

Return characters are imbedded in the file, their is no need to "insert" it in.

Their is no need for quotes unless you have data with quotes within it.

Back to Software Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums