test.html:208 Uncaught ReferenceError:未定义createtable

时间:2017-05-23 15:08:55

标签: javascript html arrays alasql

我一直在尝试创建一个可以读取excel文件的网页,然后创建一个表格。我已经让表生成部分工作,但我无法使加载部分工作。我收到的错误是我的函数没有定义。

代码:

<!DOCTYPE html>
<html>
<head>


    <title>Convert JSON Data to HTML Table Example</title>


</script>  -->
</head>
<body>
<script type="text/javascript" src="http://cdn.jsdelivr.net/alasql/0.3/alasql.min.js">
var myBooks
function createtable(){
  (function () {
    'use strict';
}
}

}

alasql('SELECT * FROM XLSX("test.xlsv")').then(function(data){
        myBooks = console.log(data);
    });


    angular
        .module('jfy')
        .factory('ImportExportToExcel', ImportExportToExcel);

    function ImportExportToExcel(alasql, $log, $rootScope) {
        return {
            importFromExcel: function (event) {
                if (event.target.files.length == 0) {
                    return false;
                }
                alasql('SELECT * FROM FILE("test.xlsv",{headers:true})', [event], function (data) {
                    $rootScope.$broadcast('import-excel-data', data);
                });
            },
            exportToExcel: function (fileName, targetData) {
                if (!angular.isArray(targetData)) {
                    $log.error('Can not export error type data to excel.');
                    return;
                }
                alasql('SELECT * INTO XLSX("' + fileName + '.xlsx",{headers:true}) FROM ?', [myBooks]);
            }
        }
    }
})();




        // EXTRACT VALUE FOR HTML HEADER. 
        // ('Book ID', 'Book Name', 'Category' and 'Price')
        var col = [];
        for (var i = 0; i < myBooks.length; i++) {
            for (var key in myBooks[i]) {
                if (col.indexOf(key) === -1) {
                    col.push(key);
                }
            }
        }

        // CREATE DYNAMIC TABLE.
        var table = document.createElement("table");

        // CREATE HTML TABLE HEADER ROW USING THE EXTRACTED HEADERS ABOVE.

        var tr = table.insertRow(-1);                   // TABLE ROW.

        for (var i = 0; i < col.length; i++) {
            var th = document.createElement("th");      // TABLE HEADER.
            th.innerHTML = col[i];
            tr.appendChild(th);
        }

        // ADD JSON DATA TO THE TABLE AS ROWS.
        for (var i = 0; i < myBooks.length; i++) {

            tr = table.insertRow(-1);

            for (var j = 0; j < col.length; j++) {
                var tabCell = tr.insertCell(-1);
                tabCell.innerHTML = myBooks[i][col[j]];
            }
        }

        // FINALLY ADD THE NEWLY CREATED TABLE WITH JSON DATA TO A CONTAINER.
        var divContainer = document.getElementById("showData");
        divContainer.innerHTML = "";
        divContainer.appendChild(table);
        object.onclick = function(){table};

}
 </script>



    <input type="button" onclick="createtable()" value="Create Table From JSON" />
    <div id="showData"></div>
</body>


</html>

0 个答案:

没有答案