I want to print a tab character to a csv file to be able to open it accurately with excell using a java PrintWriter
, but it seems like it doesn't print this character to a file.
I am printing as follows:
PrintWriter pw = new Printwriter(new FileWriter(file));
pw.print(myvariable+"\t")
Default behavior:
I just checked, if I change file extension from .csv to .xls it is opened appropriately in excell (data on different cells)... But I still do not understand the issue
.csv
= comma separated value
so if you want to use a .csv
simply use the character ,
instead of a \t
.
Tell Excel the separator for your current file
Add: sep=\t
in the first line of your .csv
this will tell excel to use this as separator. (Source: https://superuser.com/a/420025/438867)
Change the separator in all .csv text files
According to support.office.com
In Microsoft Windows, click the Start button, and then click Control Panel.
Open the Regional and Language Options dialog box.
Do one of the following:
In Windows Vista, click the Formats tab, and then click Customize this format.
In Windows XP, click the Regional Options* tab, and then click Customize.
Type a new separator in the List separator box.
Click OK twice.