帮助!从XLSX发出请求数据

时间:2018-09-06 17:03:42

标签: javascript jquery ajax get xlsx

我遇到此错误:

jquery-1.12.4.js:837 Uncaught RangeError: Maximum call stack size exceeded
    at Function.Sizzle [as find] (jquery-1.12.4.js:837)    
    at jQuery.fn.init.find (jquery-1.12.4.js:2826)   
    at HTMLTableElement.<anonymous> (datatables.min.js:101)   
    at Function.each (jquery-1.12.4.js:370)   
    at jQuery.fn.init.each (jquery-1.12.4.js:137)    
    at jQuery.fn.init.n [as dataTable] (datatables.min.js:95)   
    at XMLHttpRequest.oReq2.onload (SCV Data Catalog.aspx:1071)

我正在尝试从XLSX外部文档中获取所有数据,但是由于该文档有26k条记录,因此出现了上面的错误。当我使用具有26k条记录而不是600条记录的XLSX时,所有这些开始。

这就是我到目前为止:

var url = "externalDocumentURL";
var oReq2 = new XMLHttpRequest();
oReq2.open("GET", url, true);
oReq2.responseType = "arraybuffer";

oReq2.onload = function(e) {
var arraybuffer = oReq2.response; 

var srcName = [];
var dboName2 = [];
var tableName2 = [];
var columnName = [];
var dataType = [];
var remarks = [];

var tableStringDetail = "<div><div id='dSearch'><label id='lblD0' for='srcName'>Source Name:</label><div id='divD0'></div><label id='lblD1' for='dboName2'>Database Name:</label><div id='divD1'></div><label id='lblD2' for='tableName2'>Table Name:</label><div id='divD2'></div><label id='lblD3' for='columnName'>Column Name:</label><div id='divD3'></div><label id='lblD4' for='dataType'>Data Type:</label><div id='divD4'></div><label id='lblD5' for='remarks'>Remarks:</label><div id='divD5'></div></div><table id='tableDetail_'><thead id='header'><tr><th>Source Name</th><th>Database Name</th><th>Table Name</th><th>Column Name</th><th>Data Type</th><th>Remarks</th></tr></thead><tbody>";

var data = new Uint8Array(arraybuffer);

var arr = new Array();

for (var i = 0; i != data.length; ++i) {
    arr[i] = String.fromCharCode(data[i]);
}

var bstr = arr.join("");

var cfb = XLSX.read(bstr, { type: 'binary' });

var fieldsObjs1 = XLS.utils.sheet_to_json(cfb.Sheets['Field View']);

for (var i = 0; i < fieldsObjs1.length; i++)
{
    srcName.push(fieldsObjs1[i]["Source Name"]);
    dboName2.push(fieldsObjs1[i]["Database Name"]);
    tableName2.push(fieldsObjs1[i]["Table Name"]);
    columnName.push(fieldsObjs1[i]["Column Name"]);
    dataType.push(fieldsObjs1[i]["Data type"]);
    remarks.push(fieldsObjs1[i]["Remarks"]);
    if (remarks[i] == null || remarks[i] == undefined || remarks[i] == "") {
        remarks[i] = "";
    }

    tableStringDetail+="<tr><td class='tCol'>"+ srcName[i] +"</td><td class='tCol'>"+ dboName2[i] +"</td><td>"+ tableName2[i] +"</td><td class='tCol'>"+ columnName[i] +"</td><td class='tCol'>"+ dataType[i] +"</td><td class='tCol'>"+ remarks[i] +"</td></tr>"; 
}

tableStringDetail+=" </tbody></table></div>";

$('#tableDetail').html(tableStringDetail);
$('#tableDetail_').dataTable({"order": [0, "asc"]});

var table2 = $('#tableDetail_').DataTable();

$("div #dSearch div").each( function ( d ) {
    var selectD = $('<select class="dSelect" id="dSelect'+ d +'"><option value=""></option></select>')
        .appendTo( $(this).empty() )
        .on( 'change', function () {
            table2.column( d )
                .search( $(this).val() )
                .draw();
        } );

    table2.column( d ).data().unique().sort().each( function ( d, j ) {
        selectD.append( '<option value="'+ d +'">'+ d +'</option>' )
    } );
} );

document.getElementById("detailTab").click();
}

oReq2.send();

0 个答案:

没有答案