Search code examples
alasql

Exporting Multiple HTML tables to excel such that each HTML table is in a new column


I'm trying to use alasql to export a set of HTML tables into an excel document.

The documentation has code that looks similar to this:

var data1 = alasql('SELECT * FROM HTML("#dev-table",{headers:false})');
var data2 = alasql('SELECT * FROM HTML("#dev2-table",{headers:false})');
var data3 = alasql('SELECT * FROM HTML("#dev3-table",{headers:false})');
 //var data4 = alasql('SELECT * FROM HTML("#dev2-table",{headers:true})');
var data = data1.concat(data2, data3);
alasql('SELECT * INTO XLS("data.xls",{headers:false}) FROM ?', [data]);

The problem is that this code concatenates the data1 and data2 field so that all of the data is printed in the same column. This is not the result I desire. I want "data1" to go into column "A" and data2 to go into column "B".

I've looked through the documentation and am unsure how to get the desired result. I'm aware of the existence of "options" that include fields for specifying columns based on the data itself, but none of those examples are what I want. If this is not possible using alasql, I'm willing to use a different library or framework for this.


Solution

  • Based on this JSFiddle, http://jsfiddle.net/95j0txwx/7/

    $scope.items = [{
        name: "John Smith",
        email: "[email protected]",
        dob: "1985-10-10"
    }, {
        name: "Jane Smith",
        email: "[email protected]",
        dob: "1988-12-22"
    },
    ...
    

    I would guess that your data is not formatted correctly to be inserted.

    EDIT: JSFiddle is from documentation. https://github.com/agershun/alasql/wiki/XLSX