我想使用javascript在csv文件的列中写一个字符串。 我使用下面的代码,但它将整个字符串写入1列。
var header="Number" + ',' + "Name" + ',' + "Description" + '\n' ;
这就是我创建csv fie的方式:
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.CreateTextFile("C:\\REPORT.csv");
有什么建议吗?
答案 0 :(得分:1)
您的代码没有任何问题。很少CSV
个标准可以使用不同的字符作为分隔符,例如USA/UK CSV
使用逗号分隔符,而European CSV/DSV
使用分号分隔符。
您应该确保正确配置了您的查看器,在OpenOffice Calc
尝试打开CSV
时,您会看到the following窗口提示符,您可以在其中选择正确的分隔符。
如果您正在使用Excel:How to correctly display .csv files within Excel 2013?
答案 1 :(得分:0)
There's also an option in Windows to control the separator :
Go to "Control Panel"/"Region and Language"/"Change the date, time or number format". In the "Region and Language" window that opens, click "Additional settings..." in the "Format" Tab.
On the "numbers" tab, there is a "list separator" which you can choose between semicolon (;) and comma (,). When applying the changes and opening the file with excel again, it will be all good.
The only problem with that solution is it changes the entire system separator. So if you have other files with semicolon separator you want to open in excel, then you will have to import it as text file and change some parameters...