简体   繁体   English

如何以以下格式使用javascript将数据保存在CSV中?

[英]how to save data in CSV using javascript in the following format?

Symbol: AAPL,Company: ABC ,Price: 132.54 (nextline)
Symbol: SDF,Company: ZX Corp,Price: 132.54(nextline)

You can use the following您可以使用以下

var data = "data:text/csv;charset=utf-8,name1,city1,some other infoname2,city2,more info"

 var data = "data:text/csv;charset=utf-8,name1,city1,some other infoname2,city2,more info"; var encodedUri = encodeURI(data);
 <a href="file" download="file.scv">Download</>

You should have the above data in the variable to convert it to CSV once you have the data in the variable you can do the following.您应该在变量中有上述数据,以便在变量中有数据后将其转换为 CSV,您可以执行以下操作。

var encodedUri = encodeURI(data);
window.open(encodedUri);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM