我有一个列表,需要生成一个CSV。下面是:
[101, true, P, b, br, 2020], [101, true, P, 20, br, 2020], [101, true, P, b, breach, 2020]我写这封信是为了转换它:
var link = document.createElement('a');
link.id = 'download-csv';
link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(queries.toString().replaceAll("[","").replaceAll("],","\\r\\n").replaceAll(",",";").trim().replaceAll("]","")));
link.setAttribute('download', 'yourfiletextgoeshere.csv');
document.body.appendChild(link);
document.querySelector('#download-csv').click();生成的CSV文件如下所示:
101; true; P; b; br; 2020\r\n101; true; P; 20; br; 2020\r\n101; true; P; b; br; 2020它没有打破这一行,而是像\r\n是一个字符串一样继续。
发布于 2021-01-26 15:23:41
https://stackoverflow.com/questions/65897660
复制相似问题