Faire des fichiers à partir de l'arraie Enregistrer JS
async function saveCSV () {
// (A) ARRAY OF DATA
var array = [
["Job", "[email protected]", "123456"],
["Joe", "[email protected]", "234567"],
["Joi", "[email protected]", "345678"],
["Jon", "[email protected]", "456789"],
["Jou", "[email protected]", "987654"],
["Joy", "[email protected]", "876543"],
];
// (B) ARRAY TO CSV STRING
var csv = "";
for (let row of array) {
for (let col of row) { csv += col + ","; }
csv += "\r\n";
}
// (C) CREATE BLOB OBJECT
var myBlob = new Blob([csv], {type: "text/csv"});
// (D) FILE HANDLER & FILE STREAM
const fileHandle = await window.showSaveFilePicker({
suggestedName : "demo.csv",
types: [{
description: "CSV file",
accept: {"text/csv": [".csv"]}
}]
});
const fileStream = await fileHandle.createWritable();
// (E) WRITE FILE
await fileStream.write(myBlob);
await fileStream.close();
}
Wild Weasel