javascriptexcelblob

How to create an Excel File with javascript?


I would like to know if it is possible to create an Excel File and make it downloaded from a web page with javascript ?

Currentlly, I succes to create a .csv and make it downloaded with the following code :

var blob = new Blob([csvText], { type: 'text/csv;charset=UFT-8;' });
var link = document.createElement("a");
if (link.download !== undefined) { // feature detection
    // Browsers that support HTML5 download attribute
    var url = URL.createObjectURL(blob);
    link.setAttribute("href", url);
    link.setAttribute("download", "file.csv");
    link.style.visibility = 'hidden';
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
}

I am wondering if there is any librairies in javascript with permit to convert the file from csv format to xlsx format and make it downloaded the same way than the csv ?

The final aim is to set a template in the downlaoded xlsx.


Solution

  • There is couple of options https://github.com/stephenliberty/excel-builder.js

    Another github project with less Excel options but less worries about Excel compatibility issues can be found here: ExcellentExport.js https://github.com/jmaister/excellentexport