Skip to content

How to import and export Excel files to javascript array

Mathias Rangel Wulff edited this page Mar 14, 2017 · 4 revisions

How to import and export Excel files to javascript array?

Source: StackOverflow.com

Question

I'm currently looking for a fast and efficient way to import an Excel file into a javascript array, and export it also. I also need a way to do the same thing, but the opposite way.

Answer

For import:

    alasql('SELECT * FROM XLSX("srcfileName")'].then(function(data){
        console.log(data);
    });

For export:

    var data = [{a:!,b:10},{a:2,b:20}];
    alasql('SELECT * INTO XLSX("myfileName") FROM ?',[data]);

Import and export with interim data processing:

    alasql('SELECT * \
                INTO XLSX("myfile.xlsx",{headers:true}) \
                FROM XLSX("srcfile.xlsx",{headers:true}) \
                WHERE Age > 20 \
                GROUP BY LastName \
                HAVING COUNT(*) > 2 \
                ORDER BY LastName, FirstName');
Clone this wiki locally