使用JavaScript搜索Excel工作表

时间:2018-10-31 11:09:35

标签: javascript excel

我是JavaScript新手。 我想用JavaScript搜索一个excel工作表,所以我想将结果显示为web table.i写了下面的代码,但没有用。任何机构都可以帮助我???非常感谢。

    <script>
                function searchExcel()
            {
                var searchPhrase = document.getElementById('searchPhrase').value;
                var Worksheet = 'example.xls';
                var Excel = new ActiveXObject('Excel.Application');

                Excel.Visible = false;
                var Excel_file = Excel.Workbooks.Open(Worksheet, null, true, null,
                    "abc", null, true, null, null, false, false, null, null, null);

                var range = Excel_file.ActiveSheet.Range('A:A');
                var jsRangeArray = new VBArray(range.Value).toArray();

                var found = false;
                for(cells in jsRangeArray)
                {
                    if(jsRangeArray[cells] == searchPhrase)
                    {
                       document.getElementById("results").innerHTML = "Found";
                       found = true;
                    }
                }

                if(found == false)
                {
                    document.getElementById("results").innerHTML = "Not Found";
                }

                Excel.ActiveWorkbook.Close(true);
                Excel.Application.Quit();
                Excel = null;
            }
    </script>
    
<html>
    <head>
        <script src="js/jquery-1.12.2.js"></script>
    </head>
    <body>
        <input type="text" name="searchPhrase" />
        <a href="javascript: searchExcel();">Search</a>
        <div id="results"></div>
    </body>
</html>

0 个答案:

没有答案