简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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