# \[Solved\] CSV.write(), file opens correctly in excel, but wrong layout in text

**URL:** https://discourse.julialang.org/t/solved-csv-write-file-opens-correctly-in-excel-but-wrong-layout-in-text/56130
**Category:** General Usage
**Created:** [February 27, 2021, 8:49am UTC](https://discourse.julialang.org/t/solved-csv-write-file-opens-correctly-in-excel-but-wrong-layout-in-text/56130 "2021-02-27T08:49:10Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![AIRoebl](https://avatars.discourse-cdn.com/v4/letter/a/96bed5/32.png) [@AIRoebl](https://discourse.julialang.org/u/AIRoebl)
#### Post date: [February 27, 2021, 8:49am UTC](https://discourse.julialang.org/t/solved-csv-write-file-opens-correctly-in-excel-but-wrong-layout-in-text/56130/1 "2021-02-27T08:49:11Z")

</div>

Hi, I hope someone can help me here, I’ve been banging away at this for a day now. I’m using CSV.write() to write a dataframe to a CSV file (.txt). The output opens perfectly in excel, but the layout isn’t right in the text file. I’m doing the following:

CSV.write(“test.txt”,df,writeheader=false,newline=“\n”)

For example, what i get in excel is in columns as expected:  
a b c d  
e f g h  
i j k l  
What appears in the text file is:  
a,b,c,de,f,g,hi,j,k,l  
I want it to appear in the text file as:  
a,b,c,d  
e,f,g,h  
i, j,k,l  
when I open it in notepad (I need it in this format).

I’ve tried opening a text file and using append, and I get the same result. I’ve searched all over, and there is lots of info about reading, but very little about writing. The help seems quite sparse too. ‘opts’ is mentioned, but no other information on ‘opts’.

I’m stumped, help appreciated.  
Thanks

edit: Added commas to desired text file layout

---

<div class="post-metadata">

### Author: ![AIRoebl](https://avatars.discourse-cdn.com/v4/letter/a/96bed5/32.png) [@AIRoebl](https://discourse.julialang.org/u/AIRoebl)
#### Post date: [February 27, 2021, 1:11pm UTC](https://discourse.julialang.org/t/solved-csv-write-file-opens-correctly-in-excel-but-wrong-layout-in-text/56130/2 "2021-02-27T13:11:49Z")

</div>

Problem solved - newline changed to “\r\n”. Suspect I made the change, saved, but file was saved to different directory.

---

<div class="post-metadata">

### Author: ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)
#### Post date: [February 27, 2021, 3:43pm UTC](https://discourse.julialang.org/t/solved-csv-write-file-opens-correctly-in-excel-but-wrong-layout-in-text/56130/3 "2021-02-27T15:43:55Z")

</div>

I never specify the newline when using `CSV.write` and I’ve not had this issue. Just tested to confirm that in both VS Code and when I just `cat` to the terminal, I get tabular looking output as you want. I wonder if the issue is more to do with whatever editor you are using and less to do with the actual file.
