如何读取AngularJS中的特定列范围行数

时间:2017-12-14 15:01:30

标签: javascript angularjs excel

我正在使用AngularJS中的excel导入功能。现在通过阅读excel值可以正常工作。但我需要读取特定的列范围行数 这里我附上了我尝试过的代码和预期的输出。在这里我得到行数为7,但我需要名称和主题列行计数,只有预期行数为4有助于如何解决这个问题。

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Angular Js XLS</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.9.13/xlsx.full.min.js"></script>
        <script type="text/javascript" src="https://unpkg.com/angular-js-xlsx@0.0.3/angular-js-xlsx.js"></script>
    </head>

    <body ng-app="MyApp">

        <div ng-controller="myController">
            <js-xls onread="read" onerror="error"></js-xls>
            <!-- <input type="file" ng-change="read" onerror="error"> -->
        </div>

    </body>

    <script type="text/javascript">
        angular.module('MyApp', ['angular-js-xlsx'])
        .controller('myController', function($scope) {
            $scope.read = function (workbook) {
debugger;
                var headerNames = XLSX.utils.sheet_to_json( workbook.Sheets[workbook.SheetNames[0]], { header: 1 })[0];
                var data = XLSX.utils.sheet_to_json( workbook.Sheets[workbook.SheetNames[0]]);

                console.log(headerNames);
                console.log(data);

                for (var row in data)
                {
                    Object.keys(data[row]).forEach(function(key) {
                        console.log("Key = >" + key);
                        console.log("Value => " + data[row][key]);
                        console.log("===========================");
                    });
                }
            }

            $scope.error = function (e) {
                console.log(e);
            }
        });
    </script>

</html>

数据

enter image description here

0 个答案:

没有答案