我编写了一个轻量级的客户端 CSV 生成器库,它可能会派上用场。在https://github.com/lbrtw/csv上查看
到位后,您只需使用getFileContents
方法和window.open
or即时生成并通过电子邮件发送 CSV 文件location.href = ...
,如下所示:
var propertyOrder = ["name", "age", "height"];
var csv = new Csv(propertyOrder);
csv.add({ name : "Anders",
age : 38,
height : "178cm" });
csv.add({ name : "John Doe",
age : 50,
height : "184cm" });
var fileContents = csv.getFileContents();
var link = "mailto:" + emailAddress + "?subject=CSV&body=" + fileContents;
// This action should open the default email app:
window.location.href = link;
// , and if that doesn't work, try this instead:
window.open(link);